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