result not correct
Answeredfrom gurobipy import *
import pandas as pd
import numpy as np
n=5 #number of noeds
k=3 #number of color
Arcs=[
(1,2),
(1,5),
(2,1),
(2,3),
(2,4),
(3,2),
(3,4),
(4,2),
(4,3),
(4,5),
(5,1),
(5,4),
]
N = [i for i in range(1, n+1)]
K = [k for k in range(1,k+1)]
#create model
m=Model('Graph Coloring')
#create variables
x=m.addVars(N,K,vtype=GRB.BINARY,name='x')
y=m.addVars(K,vtype=GRB.BINARY,name='y')
#create constraints
m.addConstrs(x.sum(i,'k')==1 for i in N)
m.addConstrs(x[i,k]+x[j,k]<=y[k] for i,j in Arcs for k in K)
# objective function
m.modelSense = GRB.MINIMIZE
m.setObjective(quicksum(y[k] for k in K))
m.optimize()
Model is infeasible
Best objective -, best bound -, gap -
0
-
For infeasible model, please refer to How do I determine why my model is infeasible?
The term \(\texttt{x.sum(i,'k')}\) should read \(\texttt{x.sum(i,'*')}\).
Best regards,
Jaromił0
Please sign in to leave a comment.
Comments
1 comment