質問するログイン新規登録

質問編集履歴

4

誤字

2018/11/08 15:23

投稿

hanatarekozoman
hanatarekozoman

スコア14

title CHANGED
File without changes
body CHANGED
@@ -3,232 +3,4 @@
3
3
  と表示されました。
4
4
  調べてみると、実行構成のVM引数にCplexファイルの場所を入力しなければいけないと書かれているサイトがありました。しかし、入力して実行してみると文字化け(?)を含んだエラーが表示されました。
5
5
  Cplexファイルの場所を入力し間違えたのかと何度もやってみましたが同じ結果です。
6
- 解決方法をご存知の方、教えて頂けませんか?
6
+ 解決方法をご存知の方、教えて頂けませんか?
7
-
8
-
9
-
10
-
11
- 追記
12
-
13
-
14
- ```ここに言語を入力
15
- package numberlink;
16
-
17
-
18
-
19
- import ilog.concert.IloException;
20
- import ilog.concert.IloIntVar;
21
- import ilog.concert.IloLinearNumExpr;
22
- import ilog.cplex.IloCplex;
23
-
24
- public class numberlink1 {
25
-
26
-
27
-
28
- public static void main(String[] args) {
29
- try {
30
- IloCplex numberlink = new IloCplex();
31
- int row=4;
32
- int column=4;
33
- IloIntVar s[][] = new IloIntVar[row][column];
34
- for(int i=1;i<=row-1;i++) {
35
- for(int j=1;j<=column;j++) {
36
- s[i][j] = numberlink.boolVar();
37
- }
38
- }
39
-
40
- IloIntVar e[][] = new IloIntVar[row][column];
41
- for(int i=1;i<=row;i++) {
42
- for(int j=1;j<=column-1;j++) {
43
- e[i][j] = numberlink.boolVar();
44
- }
45
- }
46
-
47
- IloLinearNumExpr NumberMath = numberlink.linearNumExpr();
48
- IloIntVar[][] x = new IloIntVar[row][column];
49
- for(int i=1;i<=row;i++) {
50
- for(int j=1;j<=column;j++) {
51
- NumberMath.addTerm(1, x[i][j]);
52
- numberlink.addLe(NumberMath,3);
53
- numberlink.addGe(NumberMath, 1);
54
- }
55
- }
56
-
57
- IloLinearNumExpr NumberMath1_a = numberlink.linearNumExpr();
58
- NumberMath1_a.addTerm(1,x[1][1]);
59
- numberlink.addEq(NumberMath1_a,1);
60
-
61
- IloLinearNumExpr NumberMath1_b = numberlink.linearNumExpr();
62
- NumberMath1_b.addTerm(1,x[2][3]);
63
- numberlink.addEq(NumberMath1_b,1);
64
-
65
-
66
- IloLinearNumExpr NumberMath2_a = numberlink.linearNumExpr();
67
- NumberMath2_a.addTerm(1,x[1][4]);
68
- numberlink.addEq(NumberMath2_a,2);
69
-
70
- IloLinearNumExpr NumberMath2_b = numberlink.linearNumExpr();
71
- NumberMath2_b.addTerm(1,x[3][2]);
72
- numberlink.addEq(NumberMath2_b,2);
73
-
74
-
75
- IloLinearNumExpr NumberMath3_a = numberlink.linearNumExpr();
76
- NumberMath3_a.addTerm(1,x[2][2]);
77
- numberlink.addEq(NumberMath3_a,3);
78
-
79
- IloLinearNumExpr NumberMath3_b = numberlink.linearNumExpr();
80
- NumberMath3_b.addTerm(1,x[4][4]);
81
- numberlink.addEq(NumberMath3_b,3);
82
-
83
-
84
-
85
-
86
- IloLinearNumExpr MathLine = numberlink.linearNumExpr();
87
- for(int i=1;i<=row;i++) {
88
- for(int j=1;j<=column;j++) {
89
- MathLine.addTerm(1, s[i-1][j]);
90
- MathLine.addTerm(1, s[i][j]);
91
- MathLine.addTerm(1, e[i][j-1]);
92
- MathLine.addTerm(1, e[i][j]);
93
- if(i-1==0) {
94
- MathLine.addTerm(-1, s[i-1][j]);
95
- }
96
- if(i==4) {
97
- MathLine.addTerm(-1, s[i][j]);
98
- }
99
- if(j-1==0) {
100
- MathLine.addTerm(-1, e[i][j-1]);
101
- }
102
- if(j==4) {
103
- MathLine.addTerm(-1, e[i][j]);
104
- }
105
- if((i==1&&j==1)||(i==1&&j==4)||(i==2&&j==2)||(i==2&&j==3)||
106
- (i==3&&j==2)||i==4&&j==4) {
107
- numberlink.addEq(MathLine, 1);
108
- }
109
- else {numberlink.addGe(MathLine, 2);
110
- numberlink.addLe(MathLine, 0);}
111
-
112
- }
113
- }
114
-
115
- IloLinearNumExpr IfsEq1_1 = numberlink.linearNumExpr();
116
- IloLinearNumExpr IfsEq1_2 = numberlink.linearNumExpr();
117
- for(int i=1;i<=row-1;i++) {
118
- for(int j=1;j<=column;j++) {
119
- IfsEq1_1.addTerm(3,s[i][j]);
120
- IfsEq1_1.addTerm(-1,x[i][j]);
121
- IfsEq1_1.addTerm(1,x[i+1][j]);
122
- numberlink.addLe(IfsEq1_1,3);
123
-
124
- IfsEq1_2.addTerm(3,s[i][j]);
125
- IfsEq1_2.addTerm(1,x[i][j]);
126
- IfsEq1_2.addTerm(-1,x[i+1][j]);
127
- numberlink.addLe(IfsEq1_1,3);
128
- }
129
- }
130
-
131
- IloLinearNumExpr IfeEq1_1 = numberlink.linearNumExpr();
132
- IloLinearNumExpr IfeEq1_2 = numberlink.linearNumExpr();
133
- for(int i=1;i<=row;i++) {
134
- for(int j=1;j<=column-1;j++) {
135
- IfeEq1_1.addTerm(3,e[i][j]);
136
- IfeEq1_1.addTerm(-1,x[i][j]);
137
- IfeEq1_1.addTerm(1,x[i+1][j]);
138
- numberlink.addLe(IfeEq1_1,3);
139
-
140
- IfeEq1_2.addTerm(3,e[i][j]);
141
- IfeEq1_2.addTerm(1,x[i][j]);
142
- IfeEq1_2.addTerm(-1,x[i+1][j]);
143
- numberlink.addLe(IfeEq1_1,3);
144
- }
145
- }
146
-
147
-
148
-
149
- IloLinearNumExpr AllLine = numberlink.linearNumExpr();
150
- for(int i=1;i<=row;i++) {
151
- for(int j=1;j<=column-1;j++) {
152
- AllLine.addTerm(1,e[i][j]);
153
- }
154
- }
155
- for(int i=1;i<=row-1;i++) {
156
- for(int j=1;j<=column;j++) {
157
- AllLine.addTerm(1,s[i][j]);
158
- }
159
- }
160
- numberlink.addMinimize(AllLine);
161
-
162
-
163
- if(numberlink.solve()) {
164
- System.out.println("目的関数値は"+numberlink.getObjValue());
165
- for(int i=1;i<=row;i++) {
166
- for(int j=1;j<=column;j++) {
167
- System.out.println(s[i][j]+"="+numberlink.getValue(s[i][j]));
168
- System.out.println(e[i][j]+"="+numberlink.getValue(e[i][j]));
169
- System.out.println(x[i][j]+"="+numberlink.getValue(x[i][j]));
170
- }
171
- }
172
-
173
- }
174
-
175
- }
176
- catch(IloException e) {
177
- }
178
- }
179
-
180
- ```
181
-
182
-
183
- 実行構成のVM引数にCPLEXファイルの場所を入力した後実行すると
184
- �G���[: ���C���E�N���X〇〇〇\Documents\IBM\ILOG\CPLEX_Studio127�����‚���Ȃ����������[�h�ł��܂���ł���
185
- というエラーが出ます。(〇〇〇にはユーザ名が入ります。)
186
- よろしくお願いします。
187
-
188
-
189
-
190
-
191
- 追記2
192
- 以下のようなコードを入力し実行すると、エラーも出ず解が出力されました。
193
- Cplexファイルの場所を実行構成に入力せずに実行し成功したので、元のコードのエラーの原因はコード内にあるのでしょうか...?
194
-
195
- ```ここに言語を入力
196
- package testtt;
197
-
198
- import ilog.concert.IloException;
199
- import ilog.concert.IloLinearNumExpr;
200
- import ilog.concert.IloNumVar;
201
- import ilog.cplex.IloCplex;
202
-
203
- public class test1{
204
- static public void main(String[] args) {
205
- try {
206
- IloCplex cplex = new IloCplex();
207
- // create model and solve it
208
- IloNumVar x = cplex.numVar(0, Double.MAX_VALUE, "x");
209
- IloNumVar y = cplex.numVar(0, Double.MAX_VALUE, "y");
210
- IloLinearNumExpr objective = cplex.linearNumExpr();
211
- objective.addTerm(0.12, x);
212
- objective.addTerm(0.15, y);
213
-
214
- cplex.addMinimize(objective);
215
-
216
- cplex.addGe(cplex.sum(cplex.prod(60, x), cplex.prod(60, y)), 300);
217
- cplex.addGe(cplex.sum(cplex.prod(12, x), cplex.prod(6, y)), 36);
218
- cplex.addGe(cplex.sum(cplex.prod(10, x), cplex.prod(30, y)), 90);
219
-
220
- if (cplex.solve()) {
221
- System.out.println("obj = " + cplex.getObjValue());
222
- System.out.println("x = " + cplex.getValue(x));
223
- System.out.println("y = " + cplex.getValue(y));
224
- } else {
225
- System.out.println("Can not solve");
226
- }
227
- } catch (IloException e) {
228
- System.err.println("Concert exception caught: " + e);
229
- }
230
- }
231
- }
232
-
233
-
234
- ```

3

別のコードで試した結果

2018/11/08 15:23

投稿

hanatarekozoman
hanatarekozoman

スコア14

title CHANGED
File without changes
body CHANGED
@@ -183,4 +183,52 @@
183
183
  実行構成のVM引数にCPLEXファイルの場所を入力した後実行すると
184
184
  �G���[: ���C���E�N���X〇〇〇\Documents\IBM\ILOG\CPLEX_Studio127�����‚���Ȃ����������[�h�ł��܂���ł���
185
185
  というエラーが出ます。(〇〇〇にはユーザ名が入ります。)
186
- よろしくお願いします。
186
+ よろしくお願いします。
187
+
188
+
189
+
190
+
191
+ 追記2
192
+ 以下のようなコードを入力し実行すると、エラーも出ず解が出力されました。
193
+ Cplexファイルの場所を実行構成に入力せずに実行し成功したので、元のコードのエラーの原因はコード内にあるのでしょうか...?
194
+
195
+ ```ここに言語を入力
196
+ package testtt;
197
+
198
+ import ilog.concert.IloException;
199
+ import ilog.concert.IloLinearNumExpr;
200
+ import ilog.concert.IloNumVar;
201
+ import ilog.cplex.IloCplex;
202
+
203
+ public class test1{
204
+ static public void main(String[] args) {
205
+ try {
206
+ IloCplex cplex = new IloCplex();
207
+ // create model and solve it
208
+ IloNumVar x = cplex.numVar(0, Double.MAX_VALUE, "x");
209
+ IloNumVar y = cplex.numVar(0, Double.MAX_VALUE, "y");
210
+ IloLinearNumExpr objective = cplex.linearNumExpr();
211
+ objective.addTerm(0.12, x);
212
+ objective.addTerm(0.15, y);
213
+
214
+ cplex.addMinimize(objective);
215
+
216
+ cplex.addGe(cplex.sum(cplex.prod(60, x), cplex.prod(60, y)), 300);
217
+ cplex.addGe(cplex.sum(cplex.prod(12, x), cplex.prod(6, y)), 36);
218
+ cplex.addGe(cplex.sum(cplex.prod(10, x), cplex.prod(30, y)), 90);
219
+
220
+ if (cplex.solve()) {
221
+ System.out.println("obj = " + cplex.getObjValue());
222
+ System.out.println("x = " + cplex.getValue(x));
223
+ System.out.println("y = " + cplex.getValue(y));
224
+ } else {
225
+ System.out.println("Can not solve");
226
+ }
227
+ } catch (IloException e) {
228
+ System.err.println("Concert exception caught: " + e);
229
+ }
230
+ }
231
+ }
232
+
233
+
234
+ ```

2

誤字

2018/11/07 16:17

投稿

hanatarekozoman
hanatarekozoman

スコア14

title CHANGED
File without changes
body CHANGED
@@ -180,7 +180,7 @@
180
180
  ```
181
181
 
182
182
 
183
- 実行構成のVM引数にCPLEXファイルを入力した後実行すると
183
+ 実行構成のVM引数にCPLEXファイルの場所を入力した後実行すると
184
184
  �G���[: ���C���E�N���X〇〇〇\Documents\IBM\ILOG\CPLEX_Studio127�����‚���Ȃ����������[�h�ł��܂���ł���
185
185
  というエラーが出ます。(〇〇〇にはユーザ名が入ります。)
186
186
  よろしくお願いします。

1

コード、エラー内容を追記しました。

2018/11/07 06:12

投稿

hanatarekozoman
hanatarekozoman

スコア14

title CHANGED
File without changes
body CHANGED
@@ -3,4 +3,184 @@
3
3
  と表示されました。
4
4
  調べてみると、実行構成のVM引数にCplexファイルの場所を入力しなければいけないと書かれているサイトがありました。しかし、入力して実行してみると文字化け(?)を含んだエラーが表示されました。
5
5
  Cplexファイルの場所を入力し間違えたのかと何度もやってみましたが同じ結果です。
6
- 解決方法をご存知の方、教えて頂けませんか?
6
+ 解決方法をご存知の方、教えて頂けませんか?
7
+
8
+
9
+
10
+
11
+ 追記
12
+
13
+
14
+ ```ここに言語を入力
15
+ package numberlink;
16
+
17
+
18
+
19
+ import ilog.concert.IloException;
20
+ import ilog.concert.IloIntVar;
21
+ import ilog.concert.IloLinearNumExpr;
22
+ import ilog.cplex.IloCplex;
23
+
24
+ public class numberlink1 {
25
+
26
+
27
+
28
+ public static void main(String[] args) {
29
+ try {
30
+ IloCplex numberlink = new IloCplex();
31
+ int row=4;
32
+ int column=4;
33
+ IloIntVar s[][] = new IloIntVar[row][column];
34
+ for(int i=1;i<=row-1;i++) {
35
+ for(int j=1;j<=column;j++) {
36
+ s[i][j] = numberlink.boolVar();
37
+ }
38
+ }
39
+
40
+ IloIntVar e[][] = new IloIntVar[row][column];
41
+ for(int i=1;i<=row;i++) {
42
+ for(int j=1;j<=column-1;j++) {
43
+ e[i][j] = numberlink.boolVar();
44
+ }
45
+ }
46
+
47
+ IloLinearNumExpr NumberMath = numberlink.linearNumExpr();
48
+ IloIntVar[][] x = new IloIntVar[row][column];
49
+ for(int i=1;i<=row;i++) {
50
+ for(int j=1;j<=column;j++) {
51
+ NumberMath.addTerm(1, x[i][j]);
52
+ numberlink.addLe(NumberMath,3);
53
+ numberlink.addGe(NumberMath, 1);
54
+ }
55
+ }
56
+
57
+ IloLinearNumExpr NumberMath1_a = numberlink.linearNumExpr();
58
+ NumberMath1_a.addTerm(1,x[1][1]);
59
+ numberlink.addEq(NumberMath1_a,1);
60
+
61
+ IloLinearNumExpr NumberMath1_b = numberlink.linearNumExpr();
62
+ NumberMath1_b.addTerm(1,x[2][3]);
63
+ numberlink.addEq(NumberMath1_b,1);
64
+
65
+
66
+ IloLinearNumExpr NumberMath2_a = numberlink.linearNumExpr();
67
+ NumberMath2_a.addTerm(1,x[1][4]);
68
+ numberlink.addEq(NumberMath2_a,2);
69
+
70
+ IloLinearNumExpr NumberMath2_b = numberlink.linearNumExpr();
71
+ NumberMath2_b.addTerm(1,x[3][2]);
72
+ numberlink.addEq(NumberMath2_b,2);
73
+
74
+
75
+ IloLinearNumExpr NumberMath3_a = numberlink.linearNumExpr();
76
+ NumberMath3_a.addTerm(1,x[2][2]);
77
+ numberlink.addEq(NumberMath3_a,3);
78
+
79
+ IloLinearNumExpr NumberMath3_b = numberlink.linearNumExpr();
80
+ NumberMath3_b.addTerm(1,x[4][4]);
81
+ numberlink.addEq(NumberMath3_b,3);
82
+
83
+
84
+
85
+
86
+ IloLinearNumExpr MathLine = numberlink.linearNumExpr();
87
+ for(int i=1;i<=row;i++) {
88
+ for(int j=1;j<=column;j++) {
89
+ MathLine.addTerm(1, s[i-1][j]);
90
+ MathLine.addTerm(1, s[i][j]);
91
+ MathLine.addTerm(1, e[i][j-1]);
92
+ MathLine.addTerm(1, e[i][j]);
93
+ if(i-1==0) {
94
+ MathLine.addTerm(-1, s[i-1][j]);
95
+ }
96
+ if(i==4) {
97
+ MathLine.addTerm(-1, s[i][j]);
98
+ }
99
+ if(j-1==0) {
100
+ MathLine.addTerm(-1, e[i][j-1]);
101
+ }
102
+ if(j==4) {
103
+ MathLine.addTerm(-1, e[i][j]);
104
+ }
105
+ if((i==1&&j==1)||(i==1&&j==4)||(i==2&&j==2)||(i==2&&j==3)||
106
+ (i==3&&j==2)||i==4&&j==4) {
107
+ numberlink.addEq(MathLine, 1);
108
+ }
109
+ else {numberlink.addGe(MathLine, 2);
110
+ numberlink.addLe(MathLine, 0);}
111
+
112
+ }
113
+ }
114
+
115
+ IloLinearNumExpr IfsEq1_1 = numberlink.linearNumExpr();
116
+ IloLinearNumExpr IfsEq1_2 = numberlink.linearNumExpr();
117
+ for(int i=1;i<=row-1;i++) {
118
+ for(int j=1;j<=column;j++) {
119
+ IfsEq1_1.addTerm(3,s[i][j]);
120
+ IfsEq1_1.addTerm(-1,x[i][j]);
121
+ IfsEq1_1.addTerm(1,x[i+1][j]);
122
+ numberlink.addLe(IfsEq1_1,3);
123
+
124
+ IfsEq1_2.addTerm(3,s[i][j]);
125
+ IfsEq1_2.addTerm(1,x[i][j]);
126
+ IfsEq1_2.addTerm(-1,x[i+1][j]);
127
+ numberlink.addLe(IfsEq1_1,3);
128
+ }
129
+ }
130
+
131
+ IloLinearNumExpr IfeEq1_1 = numberlink.linearNumExpr();
132
+ IloLinearNumExpr IfeEq1_2 = numberlink.linearNumExpr();
133
+ for(int i=1;i<=row;i++) {
134
+ for(int j=1;j<=column-1;j++) {
135
+ IfeEq1_1.addTerm(3,e[i][j]);
136
+ IfeEq1_1.addTerm(-1,x[i][j]);
137
+ IfeEq1_1.addTerm(1,x[i+1][j]);
138
+ numberlink.addLe(IfeEq1_1,3);
139
+
140
+ IfeEq1_2.addTerm(3,e[i][j]);
141
+ IfeEq1_2.addTerm(1,x[i][j]);
142
+ IfeEq1_2.addTerm(-1,x[i+1][j]);
143
+ numberlink.addLe(IfeEq1_1,3);
144
+ }
145
+ }
146
+
147
+
148
+
149
+ IloLinearNumExpr AllLine = numberlink.linearNumExpr();
150
+ for(int i=1;i<=row;i++) {
151
+ for(int j=1;j<=column-1;j++) {
152
+ AllLine.addTerm(1,e[i][j]);
153
+ }
154
+ }
155
+ for(int i=1;i<=row-1;i++) {
156
+ for(int j=1;j<=column;j++) {
157
+ AllLine.addTerm(1,s[i][j]);
158
+ }
159
+ }
160
+ numberlink.addMinimize(AllLine);
161
+
162
+
163
+ if(numberlink.solve()) {
164
+ System.out.println("目的関数値は"+numberlink.getObjValue());
165
+ for(int i=1;i<=row;i++) {
166
+ for(int j=1;j<=column;j++) {
167
+ System.out.println(s[i][j]+"="+numberlink.getValue(s[i][j]));
168
+ System.out.println(e[i][j]+"="+numberlink.getValue(e[i][j]));
169
+ System.out.println(x[i][j]+"="+numberlink.getValue(x[i][j]));
170
+ }
171
+ }
172
+
173
+ }
174
+
175
+ }
176
+ catch(IloException e) {
177
+ }
178
+ }
179
+
180
+ ```
181
+
182
+
183
+ 実行構成のVM引数にCPLEXファイルを入力した後実行すると
184
+ �G���[: ���C���E�N���X〇〇〇\Documents\IBM\ILOG\CPLEX_Studio127�����‚���Ȃ����������[�h�ł��܂���ł���
185
+ というエラーが出ます。(〇〇〇にはユーザ名が入ります。)
186
+ よろしくお願いします。