coin-or / python-mip

Python-MIP: collection of Python tools for the modeling and solution of Mixed-Integer Linear programs
Eclipse Public License 2.0
533 stars 93 forks source link

Can variable index on tuple set ? #46

Closed qtbhappy closed 4 years ago

qtbhappy commented 4 years ago

Hi. I wonder if we can define variable indexing on tuple set? Like the following: tuple set Arc = {<1,1>,<1,2>, <1,3>, <2,3>};

float+ var x[a in Arc]; //variable on tuple set Arc

h-g-s commented 4 years ago

this would be: from mip import *

m = Model() Arcs = [(1, 1), (1, 2), (1, 3)]

create vars

x = {a: m.add_var() for a in Arcs}

constraint to select one arc

m += xsum(x[a] for a in Arcs) == 1