質問編集履歴
6
test
CHANGED
File without changes
|
test
CHANGED
@@ -32,61 +32,7 @@
|
|
32
32
|
|
33
33
|
コード
|
34
34
|
|
35
|
-
package sample;
|
36
35
|
|
37
|
-
|
38
|
-
|
39
|
-
import ilog.concert.IloException;
|
40
|
-
|
41
|
-
import ilog.concert.IloIntVar;
|
42
|
-
|
43
|
-
import ilog.concert.IloLinearNumExpr;
|
44
|
-
|
45
|
-
import ilog.concert.IloNumExpr;
|
46
|
-
|
47
|
-
import ilog.cplex.IloCplex;
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
public class sample1 {
|
54
|
-
|
55
|
-
static public void main(String[] args) throws IloException {
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
IloCplex cplex = new IloCplex();
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
cplex.setOut(null);
|
64
|
-
|
65
|
-
cplex.setWarning(null);
|
66
|
-
|
67
|
-
int c = 1;
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
//変数の定義
|
72
|
-
|
73
|
-
IloIntVar X1 = cplex.intVar(0,2);
|
74
|
-
|
75
|
-
IloIntVar X2 = cplex.boolVar();
|
76
|
-
|
77
|
-
IloIntVar X3 = cplex.intVar(0,3);
|
78
|
-
|
79
|
-
IloIntVar X4 = cplex.intVar(0,2);
|
80
|
-
|
81
|
-
cplex.addMaximize(
|
82
|
-
|
83
|
-
cplex.sum( new IloNumExpr[]{
|
84
|
-
|
85
|
-
cplex.prod(20.0, X1), cplex.prod(50.0,X2), cplex.prod(20.0, X3),
|
86
|
-
|
87
|
-
cplex.prod(50,X4} )
|
88
|
-
|
89
|
-
);
|
90
36
|
|
91
37
|
if(cplex.solve()) {
|
92
38
|
|
@@ -94,7 +40,7 @@
|
|
94
40
|
|
95
41
|
for (int i = 0; i <= 3; i++) {
|
96
42
|
|
97
|
-
for (int j = 0; j <= 2 ;
|
43
|
+
for (int j = 0; j <= 2 ; {
|
98
44
|
|
99
45
|
if(i+j!=0) {
|
100
46
|
|
5
test
CHANGED
File without changes
|
test
CHANGED
File without changes
|
4
test
CHANGED
File without changes
|
test
CHANGED
File without changes
|
3
test
CHANGED
File without changes
|
test
CHANGED
File without changes
|
2
test
CHANGED
File without changes
|
test
CHANGED
@@ -1,32 +1,6 @@
|
|
1
|
-
X1=(0,1)=X1の値
|
2
|
-
|
3
|
-
X2=(0,2)=X2の値
|
4
|
-
|
5
|
-
X3=(1,0)=X3の値
|
6
|
-
|
7
|
-
X4=(1,1)=X4の値
|
8
|
-
|
9
|
-
X5=(1,2)=X5の値
|
10
|
-
|
11
|
-
X6=(2,0)=X6の値
|
12
|
-
|
13
|
-
X7=(2,1)=X7の値
|
14
|
-
|
15
|
-
X8=(2,2)=X8の値
|
16
|
-
|
17
|
-
X9=(3,0)=X9の値
|
18
|
-
|
19
|
-
X10=(3,1)=X10の値
|
20
|
-
|
21
|
-
X11=(3,2)=X11の値 という形にしたいです。
|
22
|
-
|
23
|
-
|
24
|
-
|
25
1
|
下記のコードで実行したところ、下のようなエラーが出てしまいます。
|
26
2
|
|
27
3
|
原因がわかる方、よろしくお願いします。
|
28
|
-
|
29
|
-
また、改善点やスマートな書き方があれば、教えて頂きたいです。
|
30
4
|
|
31
5
|
|
32
6
|
|
@@ -104,41 +78,15 @@
|
|
104
78
|
|
105
79
|
IloIntVar X4 = cplex.intVar(0,2);
|
106
80
|
|
107
|
-
IloIntVar X5 = cplex.boolVar();
|
108
|
-
|
109
|
-
IloIntVar X6 = cplex.boolVar();
|
110
|
-
|
111
|
-
IloIntVar X7 = cplex.boolVar();
|
112
|
-
|
113
|
-
IloIntVar X8 = cplex.boolVar();
|
114
|
-
|
115
|
-
IloIntVar X9 = cplex.boolVar();
|
116
|
-
|
117
|
-
IloIntVar X10 = cplex.boolVar();
|
118
|
-
|
119
|
-
IloIntVar X11 = cplex.boolVar();
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
//目的関数の最大化
|
124
|
-
|
125
81
|
cplex.addMaximize(
|
126
82
|
|
127
83
|
cplex.sum( new IloNumExpr[]{
|
128
84
|
|
129
85
|
cplex.prod(20.0, X1), cplex.prod(50.0,X2), cplex.prod(20.0, X3),
|
130
86
|
|
131
|
-
cplex.prod(50.0,X4), cplex.prod(80.0, X5), cplex.prod(50.0, X6),
|
132
|
-
|
133
|
-
cplex.prod(90.0,X7), cplex.prod(110.0, X8), cplex.prod(100.0,X9),
|
134
|
-
|
135
|
-
|
87
|
+
cplex.prod(50,X4} )
|
136
88
|
|
137
89
|
);
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
//モデルを解く
|
142
90
|
|
143
91
|
if(cplex.solve()) {
|
144
92
|
|
@@ -150,9 +98,9 @@
|
|
150
98
|
|
151
99
|
if(i+j!=0) {
|
152
100
|
|
153
|
-
for (int k = 0; k<=
|
101
|
+
for (int k = 0; k<=4; k++) {
|
154
102
|
|
155
|
-
IloIntVar[] num = {X1,X2,X3,X4
|
103
|
+
IloIntVar[] num = {X1,X2,X3,X4};
|
156
104
|
|
157
105
|
System.out.printf("X%d=(%d,%d)=%d \n", c++, i, j,num[k]);
|
158
106
|
|
1
test
CHANGED
File without changes
|
test
CHANGED
File without changes
|