0
Gurobi 7.0.2でPython 2.7.12を使用して次の制約を追加しようとしています。Gurobi制約をサブセットで作成
私はJのリストを持っている:
J
[u'Capability Investments',
u'Facilities',
u'Mission #1',
u'Mission #2',
u'New Program Readiness',
u'Site Support',
u'Transformation',
u'Waste Mgt']
と私のリスト私は次のとおりです。
I
[u'Capability Investments', u'Capability Investments', u'Capability Investments',
u'Capability Investments', u'Capability Investments', u'Site Support',
u'Site Support', u'Site Support', u'Site Support', u'Site Support', u'Site Support',
u'Site Support', u'Site Support', u'Site Support', u'Site Support', u'Site Support',
u'Site Support', u'Site Support', u'Site Support', u'Site Support', u'Site Support',
u'Site Support', u'Site Support', u'Facilities', u'Facilities', u'Facilities',
u'Facilities', u'Facilities', u'Facilities', u'Facilities', u'Facilities',
u'Facilities', u'Facilities', u'Facilities', u'Facilities', u'Facilities', u'Facilities',
u'Facilities', u'Facilities', u'Facilities', u'Facilities', u'Facilities', u'Facilities',
u'Facilities', u'Facilities', u'Facilities', u'Facilities', u'Facilities', u'Facilities',
u'Facilities', u'Facilities', u'Facilities', u'Facilities', u'Facilities', u'Facilities',
u'Facilities', u'Facilities', u'Facilities', u'Facilities', u'Facilities', u'Facilities',
u'Facilities', u'Facilities', u'Facilities', u'Facilities', u'Facilities', u'Facilities',
u'Facilities', u'Facilities', u'Facilities', u'Facilities', u'Facilities', u'Facilities',
u'Facilities', u'Facilities', u'Facilities', u'Facilities', u'Facilities', u'Facilities',
u'Facilities', u'Facilities', u'Facilities', u'Facilities', u'Facilities', u'Facilities',
u'Facilities', u'Facilities', u'Facilities', u'Facilities', u'Facilities', u'Facilities',
u'Facilities', u'Facilities', u'Facilities', u'Facilities', u'Facilities', u'Facilities',
u'Facilities', u'Facilities', u'Facilities', u'Facilities', u'Facilities', u'Facilities',
u'Facilities', u'Facilities', u'Facilities', u'Facilities', u'Facilities', u'Facilities',
u'Facilities', u'Facilities', u'Facilities', u'Facilities', u'Facilities', u'Facilities',
u'Facilities', u'Facilities', u'Facilities', u'Facilities', u'Facilities', u'Facilities',
u'Facilities', u'Facilities', u'Facilities', u'Facilities', u'Facilities', u'Facilities',
u'Facilities', u'Facilities', u'Facilities', u'Facilities', u'Facilities', u'Facilities',
u'Facilities', u'Facilities', u'Facilities', u'Facilities', u'Facilities', u'Facilities',
u'Facilities', u'Facilities', u'Facilities', u'Facilities', u'Facilities', u'Facilities',
u'Facilities', u'Facilities', u'Facilities', u'Facilities', u'Facilities', u'Facilities',
u'Facilities', u'Facilities', u'Facilities', u'Facilities', u'Facilities', u'Facilities',
u'Facilities', u'Facilities', u'Facilities', u'Facilities', u'Facilities', u'Facilities',
u'Mission #2', u'Mission #2', u'Mission #2', u'Mission #2', u'Waste Mgt', u'Waste Mgt',
u'Waste Mgt', u'Waste Mgt', u'Waste Mgt', u'Waste Mgt', u'Waste Mgt', u'Waste Mgt',
u'Waste Mgt', u'Waste Mgt', u'Waste Mgt', u'Waste Mgt', u'Waste Mgt', u'Transformation',
u'Transformation', u'Transformation', u'Transformation', u'Transformation',
u'Capability Investments', u'Mission #2', u'Mission #2', u'Mission #1', u'Mission #1',
u'Mission #1', u'Mission #1', u'Mission #1', u'Mission #1', u'Facilities',
u'New Program Readiness', u'New Program Readiness', u'New Program Readiness',
u'Transformation', u'Site Support', u'Site Support', u'Site Support', u'Site Support',
u'Site Support', u'Site Support', u'Mission #1']
私の失敗の試み:
for i in I:
for j in J:
if i == j:
m.addConstr(quicksum(c[i]*x[i])<=f[j])
第一の理由ファーilは私のリストを列挙していないので、このような制約の追加は、変数定義との矛盾を引き起こします。つまり、x変数はx [0]、x [1]、x [2]、x [3] ....これらの名前を "Capability Investments、Facilities、etc."私の指標として。私の問題を解決するために、どんな貢献も感謝しています。あなたのポストの上部の中
あなたのリストは数式と一致しないフラットリストです。 –
@Davidと一致しないことが分かりますが、どのように動作させることができますか? – user8028576
私はリストを列挙し、タプルを作成しました: 'J = list(enumerate(J)) I = list(enumerate(I))'しかし、まだあなたの式を適用できませんでした。 。 – user8028576