From 301670b3506b40e5abcd129b6a77a1ea0f5a8f22 Mon Sep 17 00:00:00 2001 From: Yu Cong Date: Thu, 23 Oct 2025 10:21:26 +0800 Subject: [PATCH] PGM results and bipartite code --- bipartite.sage | 61 +++++++++++++++++++++++++++ projection.out | 108 ++++++++++++++++++++++++++++++++++++++++++++++++ projection.sage | 15 ++++--- 3 files changed, 179 insertions(+), 5 deletions(-) create mode 100644 bipartite.sage create mode 100644 projection.out diff --git a/bipartite.sage b/bipartite.sage new file mode 100644 index 0000000..3bc2447 --- /dev/null +++ b/bipartite.sage @@ -0,0 +1,61 @@ +# cogirth-packing gap of projections of graphic matroids + +from sage.all import * +from sage.matroids.all import * +from sage.graphs.all import * +import gurobipy as gp +from gurobipy import GRB + +env = gp.Env(empty=True) +env.setParam("OutputFlag",0) +env.start() + +def representative_vectors(m, n): + for w1 in range(m+1): + for w2 in range(n+1): + v = [0]*(m+n) + v[:w1] = [1]*w1 + v[m:m+w2] = [1]*w2 + yield tuple(v) + +def cogirthip(bases, integral=true): + model = gp.Model("mip1",env=env) + # model.Params.LogToConsole = 0 + groundset=frozenset() + for B in bases: groundset=groundset|frozenset(B) + x = dict() + if integral: + for e in groundset: x[e]=model.addVar(vtype=GRB.BINARY) + else: + for e in groundset: x[e]=model.addVar(vtype=GRB.CONTINUOUS,lb=0) + model.setObjective(gp.quicksum([x[e] for e in groundset]), GRB.MINIMIZE) + for B in bases: + model.addConstr(gp.quicksum([x[e] for e in B])>=1) + model.optimize() + return model.ObjVal + + +# cnt=0 # actual number of instances tested +# f = lambda g: g.is_connected() +for N in range(2,10): + for M in range(N,10): + g=graphs.CompleteBipartiteGraph(N,M) + A=g.incidence_matrix() + n,m = A.dimensions() + maxgap = 0 + for v in representative_vectors(N,M): + # cnt=cnt+1 + v_col=matrix(v).transpose() + A_t=A.augment(v_col) + # print(A_t) + MM=Matroid(matrix=A_t,field=GF(2))/m #contract the last element + # print(M) + bases=MM.bases() + strength=cogirthip(bases,integral=false) + cogirth =cogirthip(bases,integral=true) + gap = cogirth/strength + if gap > maxgap: + maxgap = gap + maxcol = v + + print(f"K_{{{N},{M}}}, gap = {maxgap}, column = {v}") diff --git a/projection.out b/projection.out new file mode 100644 index 0000000..2108156 --- /dev/null +++ b/projection.out @@ -0,0 +1,108 @@ +################################## +1.0 +[1 0 0 1] +[0 1 0 1] +[0 0 1 0] +[1 1 1 0] +################################## +################################## +1.3333333333333333 +[1 0 0 1] +[0 1 0 1] +[0 0 1 1] +[1 1 1 1] +################################## +################################## +1.4999999999999998 +[1 0 0 0 1] +[0 1 0 0 1] +[0 0 1 0 1] +[0 0 0 1 1] +[1 1 1 1 0] +################################## +################################## +1.5 +[1 1 0 0 0 0 1] +[0 0 1 1 0 0 1] +[0 0 0 0 1 1 1] +[1 0 1 0 1 0 0] +[0 1 0 1 0 1 1] +################################## +################################## +1.7142857142857137 +[1 1 0 0 0 0 0 1] +[0 0 1 1 0 0 0 1] +[0 0 0 0 1 1 0 1] +[1 0 1 0 1 0 1 1] +[0 1 0 1 0 1 1 0] +################################## +################################## +1.7142857142857142 +[1 1 0 0 0 0 0 1] +[0 0 1 1 0 0 0 1] +[0 0 0 0 1 1 0 1] +[0 0 0 0 0 0 1 1] +[1 0 1 0 1 0 0 0] +[0 1 0 1 0 1 1 0] +################################## +################################## +2.0 +[1 1 0 0 0 0 0 0 1] +[0 0 1 1 0 0 0 0 1] +[0 0 0 0 1 1 0 0 1] +[0 0 0 0 0 0 1 1 1] +[1 0 1 0 1 0 1 0 0] +[0 1 0 1 0 1 0 1 0] +################################## +################################## +2.1333333333333337 +[1 1 1 1 1 0 0 0 0 0 0 0 0 0 0 1] +[1 0 0 0 0 1 1 1 1 0 0 0 0 0 0 1] +[0 1 0 0 0 1 0 0 0 1 1 1 0 0 0 1] +[0 0 1 0 0 0 1 0 0 1 0 0 1 1 0 1] +[0 0 0 1 0 0 0 1 0 0 1 0 1 0 1 1] +[0 0 0 0 1 0 0 0 1 0 0 1 0 1 1 1] +################################## +################################## +2.1428571428571423 +[1 1 1 0 0 0 0 0 0 0 0 0 0 0 1] +[0 0 0 1 1 1 0 0 0 0 0 0 0 0 1] +[0 0 0 0 0 0 1 1 1 0 0 0 0 0 1] +[0 0 0 0 0 0 0 0 0 1 1 1 0 0 1] +[1 0 0 1 0 0 1 0 0 1 0 0 1 0 1] +[0 1 0 0 1 0 0 1 0 0 1 0 0 1 1] +[0 0 1 0 0 1 0 0 1 0 0 1 1 1 0] +################################## +################################## +2.1818181818181817 +[1 1 0 0 0 0 0 0 0 0 0 1] +[0 0 1 1 0 0 0 0 0 0 0 1] +[0 0 0 0 1 1 0 0 0 0 0 1] +[0 0 0 0 0 0 1 1 0 0 0 1] +[0 0 0 0 0 0 0 0 1 1 0 1] +[1 0 1 0 1 0 0 0 0 0 1 1] +[0 1 0 1 0 0 1 0 1 0 0 0] +[0 0 0 0 0 1 0 1 0 1 1 0] +################################## +################################## +2.181818181818182 +[1 1 0 0 0 0 0 0 0 0 0 1] +[0 0 1 1 0 0 0 0 0 0 0 1] +[0 0 0 0 1 1 0 0 0 0 0 1] +[0 0 0 0 0 0 1 1 0 0 0 1] +[0 0 0 0 0 0 0 0 1 1 0 1] +[1 0 1 0 1 0 0 0 0 0 1 0] +[0 1 0 1 0 0 1 0 1 0 0 1] +[0 0 0 0 0 1 0 1 0 1 1 0] +################################## +################################## +2.4000000000000004 +[1 1 1 0 0 0 0 0 0 0 0 0 0 0 0 1] +[0 0 0 1 1 1 0 0 0 0 0 0 0 0 0 1] +[0 0 0 0 0 0 1 1 1 0 0 0 0 0 0 1] +[0 0 0 0 0 0 0 0 0 1 1 1 0 0 0 1] +[0 0 0 0 0 0 0 0 0 0 0 0 1 1 1 1] +[1 0 0 1 0 0 1 0 0 1 0 0 1 0 0 1] +[0 1 0 0 1 0 0 1 0 0 1 0 0 1 0 1] +[0 0 1 0 0 1 0 0 1 0 0 1 0 0 1 1] +################################## diff --git a/projection.sage b/projection.sage index e6eb77e..a15d080 100644 --- a/projection.sage +++ b/projection.sage @@ -29,8 +29,9 @@ def cogirthip(bases, integral=true): cnt=0 # actual number of instances tested +maxgap=0 f = lambda g: g.is_connected() -for N in range(8,20): +for N in range(4,10): for g in filter(f, graphs(N)): A=g.incidence_matrix() n,m = A.dimensions() @@ -47,9 +48,13 @@ for N in range(8,20): strength=cogirthip(bases,integral=false) cogirth =cogirthip(bases,integral=true) gap = cogirth/strength - if gap > 3.01: - print(f"bad example! gap={gap}") + # maxgap=max(gap,maxgap) + if gap > maxgap: + maxgap = gap + print(f"find a large gap: {gap}") with open("projection.out", "a") as file: - file.write(str(gap)+"\n"+str(A_t)+"\n") + file.write("##################################\n" + +str(gap)+"\n"+str(A_t) + +"\n##################################\n") if cnt%100==0: - print(f"#{cnt},n={n},m={m}") \ No newline at end of file + print(f"#{cnt}, n={n}, max gap = {maxgap}") \ No newline at end of file