回答編集履歴
1
面積を返す式をLpAffineExpression で作ってみました。
test
CHANGED
@@ -25,3 +25,31 @@
|
|
25
25
|
print([parts[key].value() for key in ['A','B','C','D']])
|
26
26
|
|
27
27
|
```
|
28
|
+
|
29
|
+
|
30
|
+
|
31
|
+
追記 面積を返す式をLpAffineExpression で作ってみました。
|
32
|
+
|
33
|
+
|
34
|
+
|
35
|
+
```python
|
36
|
+
|
37
|
+
import pulp
|
38
|
+
|
39
|
+
|
40
|
+
|
41
|
+
problem = pulp.LpProblem('test', pulp.LpMaximize)
|
42
|
+
|
43
|
+
parts = pulp.LpVariable.dicts('part_X', ['A','B','C','D'], 0, 1, "Binary")
|
44
|
+
|
45
|
+
part_X_area = pulp.LpAffineExpression(zip(parts.values(), [4, 9, 16, 25]))
|
46
|
+
|
47
|
+
part_X_count = pulp.LpAffineExpression(zip(parts.values(), [1, 1, 1, 1]))
|
48
|
+
|
49
|
+
part_X_constraints = pulp.LpConstraint(part_X_count, 0, 'part_X', 1)
|
50
|
+
|
51
|
+
problem += part_X_area
|
52
|
+
|
53
|
+
problem += part_X_constraints
|
54
|
+
|
55
|
+
```
|