Graph coloring with intervals Gurobi constraints

穿精又带淫゛_ 提交于 2019-12-02 04:17:50

The interval list I[i] should be defined for each node separately:

I = []
for i in G.nodes():
    Ii = []
    for z in Z:
        for u in range (z, len(Z)):
            if u - z >= G.degree(i) - 1:
                Ii.append(tuple((z, u)))
    I.apppend(Ii)

The usage of I must then be changed to something like this:

indices2 = []

for i in G.nodes(): 
    for interval in I[i]: 
        indices2.append(tuple((i,interval)))

Variables y should now only be created once:

y = mdic.addVars(indices2, vtype = gb.GRB.BINARY)

Constraint 2c must also be changed because in your screenshot the right sum iterates only over a subset of I:

for u in U:
    for z in Z:

        y_sum = 0
        for z1,z2 in I[u]:
            if z1 <= z and z <= z2:
                y_sum += y[u,(z1,z2)]

        mdic.addConstr((x.sum(u,'*',z) + x.sum('*',u,z)) <= y_sum, name='different_colors')
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!