4 Copyright (c) by Joao Pedro PEDROSO and Mikio KUBO, 2012
7 from pyscipopt
import Model, quicksum, multidict
10 """ssp -- model for the stable set problem
12 - V: set/list of nodes in the graph
13 - E: set/list of edges in the graph
14 Returns a model, ready to be solved.
20 x[i] = model.addVar(vtype=
"B", name=
"x(%s)"%i)
23 model.addCons(x[i] + x[j] <= 1,
"Edge(%s,%s)"%(i,j))
25 model.setObjective(
quicksum(x[i]
for i
in V),
"maximize")
33 """make_data: prepare data for a random graph
35 - n: number of vertices
36 - prob: probability of existence of an edge, for each pair of vertices
37 Returns a tuple with a list of vertices and a list edges.
40 E = [(i,j)
for i
in V
for j
in V
if i < j
and random.random() < prob]
44 if __name__ ==
"__main__":
50 print(
"Optimal value:", model.getObjVal())
53 print(
"Maximum stable set:")
54 print([i
for i
in V
if model.getVal(x[i]) > 0.5])