로드 중...
검색 중...
일치하는 항목 없음
Transport12.java
1패키지com.크레이지 슬롯examples.transport;
2
3가져오기java.io.파일;
4가져오기java.io.PrintStream;
5가져오기java.util.ArrayList;
6가져오기java.util.Collections;
7가져오기java.util.List;
8
11가져오기 com.게임.API.GAMSequation;
12가져오기 com.게임.API.GAMSequationRecord;
15가져오기 com.게임.API.GAMSJob;
16가져오기 com.게임.API.GAMSModelInstance;
18가져오기 com.게임.API.GAMSModifier;
22가져오기 com.게임.API.GAMSSet;
23가져오기 com.게임.API.GAMSSetRecord;
24가져오기 com.게임.API.GAMSSymbol;
26가져오기 com.게임.API.GAMSVariableRecord;
28가져오기 com.게임.API.GAMSWorkspaceInfo;
29
34공개 클래스운송12
35{
36 공개 정적 무효메인(문자열[] 인수)
37{
38 // 명령줄 인수에서 작업공간 정보 확인
40 if(args.length > 0)
41wsInfo.setSystemDirectory( 인수[0] );
42 // 디렉토리 생성
43파일 WorkingDirectory =신규파일(System.getProperty("user.dir"), "교통12");
44workingDirectory.mkdir();
45wsInfo.setWorkingDirectory(workingDirectory.getAbsolutePath());
46 // 작업공간 생성
48
49 // 작업을 실행하여 체크포인트를 초기화합니다.
51
52 GAMSJobt12 = ws.addJobFromString(모델);
53t12.실행(cp);
54
55 // ModelInstance를 생성하고 다른 스칼라 bmult를 사용하여 여러 번 해결합니다.
57
58 더블[] bmultilist =신규 더블[] { 0.6, 0.7, 0.8, 0.9, 1.0, 1.1, 1.2, 1.3 };
59
61
62 GAMSSetscen1 = db1.추가세트("장면", 1,"");
63 크레이지 슬롯매개변수bmult = db1.addParameter("b다중 목록", "", 장면1);
64 크레이지 슬롯매개변수zscen1 = db1.addParameter("zscen", "", 장면1);
65
66 inti = 0;
67 for (더블b : b멀티리스트)
68{
69bmult.addRecord("들"+ i).setValue(b);
70scen1.addRecord("들"+ i);
71i++;
72}
73
74 GAMSSetdict = db1.추가세트("dict",3,"");
75dict.addRecord(신규문자열[] scen1.getName(),"시나리오", ""} );
76dict.addRecord(신규문자열[]"bmult", "매개변수", bmult.getName() );
77dict.addRecord(신규문자열[]"z", "레벨", zscen1.getName() );
78
79GUSSCall(dict, mi,"운송은 lp min z를 사용합니다", , , );//System.out);
80
81 for (GAMSParameterRecordrec : db1.getParameter(zscen1.getName()))
82System.out.println(rec.getKey(0) +" 객체: "+ rec.getValue());
83
84 //*******************
85
88
89 GAMSSetscen2 = db2.추가세트("장면", 1,"");
90 크레이지 슬롯매개변수zscen2 = db2.addParameter("zscen", "", 장면2);
92
93 for (intj = 0; j<4; j++)
94 for (GAMSSetRecordirec : t12.아웃DB().getSet("나"))
95 for (GAMSSetRecordjrec : t12.아웃DB().getSet("j"))
96{
97문자열[] 키 =신규문자열[]"들"+ j, irec.getKey(0), jrec.getKey(0) ;
98xup.addRecord(keys).setValue(j+1);
99}
100scen2.addRecord("들"+ j);
101}
102
103 GAMSSetdict2 = db2.추가세트("dict", 3,"");
104dict2.addRecord(신규문자열[] scen2.getName(),"시나리오", ""} );
105dict2.addRecord(신규문자열[]"x", "낮은", xup.getName() );
106dict2.addRecord(신규문자열[]"z", "레벨", zscen2.getName() );
107
108GUSSCall(dict2, mi2,"운송은 lp min z를 사용합니다", , , System.out);
109
110 for (GAMSParameterRecordrec:db2.getParameter(zscen2.getName()))
111System.out.println(rec.getKey(0) +" obj: "+ rec.getValue());
112}
113
114 // 인스턴스화되지 않은 GAMSModelInstance를 사용하여 호출해야 합니다.
115 정적 무효GUSS콜(GAMSSetdict,GAMSModelInstancemi, StringsolvStatement, GAMSOptions opt,GAMSModelInstanceOptmiOpt, PrintStream 출력)
116{
117List<Object[]> modifierList = Collections.synchronizedList(신규ArrayList<Object[]>() );
118
119 if(dict.getDimension() != 3)
120 던지기 신규 크레이지 슬롯예외("사전은 3차원이어야 합니다");
121
122문자열 scenName = dict.getFirstRecord(신규문자열[]" ", "시나리오", " ").getKey(0);
123 GAMSSetscenSymbol = dict.getDatabase().getSet(scenName);
124
125 for (GAMSSetRecordrec : 사전)
126{
127
128 if(rec.getKey(1).toLowerCase().equals("시나리오"))
129 계속;
130 if(rec.getKey(1).toLowerCase().equals("매개변수"))
131{
132 intmodifierDim = dict.getDatabase().getParameter(rec.getKey(2)).getDimension() - scenSymbol.getDimension();
133 if(modifierDim < 0)
134 던지기 신규 크레이지 슬롯예외("크기"+ rec.getKey(2) +"너무 작습니다");
135 GAMSModifier모드 =신규 GAMSModifier(mi.SyncDB().addParameter(rec.getKey(0), modifierDim,""));
136 크레이지 슬롯매개변수param = dict.getDatabase().getParameter( rec.getKey(2));
137modifierList.add(
138 신규객체[] mod, param
139);
140}
141 그밖에 if((rec.getKey(1).toLowerCase().equals("낮은")) ||
142(rec.getKey(1).toLowerCase().equals("상단")) ||
143(rec.getKey(1).toLowerCase().equals("고정됨")))
144{
145 intmodifierDim = (int) (dict.getDatabase().getParameter(rec.getKey(2)).getDimension() - scenSymbol.getDimension());
146 if(modifierDim < 0)
147 던지다 신규 크레이지 슬롯예외("크기"+ rec.getKey(2) +"너무 작습니다");
148 크레이지 슬롯변수modifierVar =;
149 시도해 보세요{
150modifierVar = dict.getDatabase().getVariable(rec.getKey(0));
151}
152 잡기(예외 e)
153modifierVar = mi.SyncDB().추가변수(rec.getKey(0),modifierDim, GAMSGlobals.VarType.FREE,"");
154}
155 if(rec.getKey(1).toLowerCase().equals("낮은"))
156{
157 GAMSModifier모드 =신규 GAMSModifier(modifierVar, GAMSGlobals.UpdateAction.LOWER, mi.SyncDB().addParameter(rec.getKey(2), modifierDim,""));
158 크레이지 슬롯매개변수param = dict.getDatabase().getParameter(rec.getKey(2));
159modifierList.add(
160 신규객체[] mod , param
161);
162}
163 그밖에 if(rec.getKey(1).toLowerCase().equals("상단"))
164{
165 GAMSModifier모드 =신규 GAMSModifier(modifierVar, GAMSGlobals.UpdateAction.UPPER, mi.SyncDB().addParameter(rec.getKey(2), modifierDim,""));
166 크레이지 슬롯매개변수param = dict.getDatabase().getParameter(rec.getKey(2));
167modifierList.add(
168 신규객체[] mod , param
169);
170}
171 그밖에{// 수정됨
172 GAMSModifier모드 =신규 GAMSModifier(modifierVar, GAMSGlobals.UpdateAction.FIXED, mi.SyncDB().addParameter(rec.getKey(2), modifierDim,""));
173 크레이지 슬롯매개변수param = dict.getDatabase().getParameter(rec.getKey(2));
174modifierList.add(
175 신규객체[] mod , param
176);
177}
178}
179 그밖에 if((rec.getKey(1).toLowerCase().equals("레벨")) || (rec.getKey(1).toLowerCase().equals("한계")))
180{
181 // GAMSDatabase에 매개변수가 있는지 확인하세요. 없으면 예외가 발생합니다.
182@SuppressWarnings("미사용")
183 크레이지 슬롯매개변수x = dict.getDatabase().getParameter(rec.getKey(2));
184}
185 그밖에
186 던지기 신규 크레이지 슬롯예외("UpdateAction을 처리할 수 없습니다."+ rec.getKey(1));
187}
188
189목록<GAMSModifier> mL = Collections.synchronizedList(신규ArrayList<GAMSModifier>() );
190 for(Object[] 튜플 : modifierList)
191 if(튜플[0] 인스턴스ofGAMSModifier)
192mL.추가( (GAMSModifier) 튜플[0] );
193}
194 GAMSModifier[] 모드 = (GAMSModifier[]) mL.toArray(신규 GAMSModifier[mL.size()]);
195
196mi.인스턴스화(solveStatement, opt, mods);
197
198List<Object[]> outList = Collections.synchronizedList(신규ArrayList<Object[]>() );
199
200 for (GAMSSetRecords : scenSymbol)
201{
202 for(Object[] 튜플 : modifierList)
203{
206
207 GAMSModifierm = (GAMSModifier) 튜플[0];
208 if(m.getDataSymbol() ==)
210 그밖에
211p = m.getDataSymbol();
212
213 // SymbolUpdateType=BaseCase를 구현함
214p.clear();
215
217문자열[] 필터 =신규문자열[pscen.getDimension()];
218 (inti = 0; i < scenSymbol.getDimension(); 나++)
219필터[i] = s.getKey(i);
220 for (inti = scenSymbol.getDimension(); i < pscen.getDimension(); 나++)
221필터[i] =" ";
222
223 시도해 보세요
224{
225rec = pscen.getFirstRecord(필터);
227 계속;
228}
229
230문자열[] myKeys =신규문자열[p.getDimension()];
231 for (inti = 0; i < p.getDimension(); 나++)
232myKeys[i] = rec.getKey(scenSymbol.getDimension()+i);
233p.addRecord(myKeys).setValue(rec.getValue() );
234}그동안(rec.moveNext());
235}
236
238 if(outList.size() == 0)
239{
240 for (GAMSSetRecordrec : 사전)
241{
242 if((rec.getKey(1).toLowerCase().equals("레벨")) || (rec.getKey(1).toLowerCase().equals("한계")))
243{
244 GAMSSymbol<?>sym = mi.SyncDB().getSymbol(rec.getKey(0));
245 크레이지 슬롯매개변수param = dict.getDatabase().getParameter(rec.getKey(2));
246문자열 str = rec.getKey(1).toLowerCase();
247outList.add(
248 신규객체[] Sym, param, str
249);
250}
251}
252}
253 for(객체[] 튜플 : outList)
254{
255 GAMSSymbol<?>기호 = (GAMSSymbol<?>) 튜플[0];
257문자열 str = (문자열)튜플[2];
258문자열[] myKeys =신규문자열[scenSymbol.getDimension() + 기호.getFirstRecord().getKeys().length];
259 for (inti = 0; i < scenSymbol.getDimension(); 나++)
260myKeys[i] = s.getKey(i);
261
262 if((str.equals("레벨")) &&(기호 인스턴스크레이지 슬롯변수))
263{
265 for (GAMSVariableRecordrec : var)
266{
267 for (inti = 0; i < Rec.getKeys().length; 나++)
268myKeys[scenSymbol.getDimension() + i] = s.getKey(i);
269param.addRecord(myKeys).setValue( rec.getLevel() );
270}
271}
272 그밖에 if((str.equals("레벨")) && (기호 인스턴스GAMSequation))
273{
274 GAMSequationeq = (GAMSequation) 기호;
275 for (GAMSequationRecordrec : eq)
276{
277 for (inti = 0; i < Rec.getKeys().length; 나++)
278myKeys[scenSymbol.getDimension() + i] = s.getKey(i);
279param.addRecord(myKeys).setValue( rec.getLevel() );
280}
281}
282 그밖에 if((str.equals("한계")) && (기호 인스턴스크레이지 슬롯변수))
283{
285 for (GAMSVariableRecordrec : var)
286{
287 (inti = 0; i < Rec.getKeys().length; 나++)
288myKeys[scenSymbol.getDimension() + i] = s.getKey(i);
289param.addRecord(myKeys).setValue( rec.getMarginal() );
290}
291}
292 그밖에 if((str.equals("한계")) && (기호 인스턴스GAMSequation))
293{
294 GAMSequationeq = (GAMSequation) 기호;
295 for (GAMSequationRecordrec : eq)
296{
297 for (inti = 0; i < Rec.getKeys().length; 나++)
298myKeys[scenSymbol.getDimension() + i] = s.getKey(i);
299param.addRecord(myKeys).setValue( rec.getMarginal() );
300}
301}
302}
303}
304}
305
306 정적문자열 모델 =
307 "\n 세트" +
308 " 나는 식물 통조림 / 시애틀, 샌디에고 / \n" +
309 " j 마켓 / 뉴욕, 시카고, 토피카 / ; \n" +
310 " \n" +
311 "매개변수 \n" +
312 " \n" +
313 " a(i) 경우에 따라 공장 i의 용량 \n" +
314 " / 시애틀 350 \n" +
315 " 샌디에고 600 / \n" +
316 " \n" +
317 " b(j) 경우의 시장 j 수요 \n" +
318 " / 뉴욕 325 \n" +
319 " 시카고 300 \n" +
320 " 토피카 275 / ; \n" +
321 " \n" +
322 "테이블 d(i,j) 거리(천 마일 단위) \n" +
323 " 뉴욕 시카고 토피카 \n" +
324 " 시애틀 2.5 1.7 1.8 \n" +
325 " 샌디에고 2.5 1.8 1.4 ; \n" +
326 " \n" +
327 "천 마일당 케이스당 달러 단위의 스칼라 f 화물 /90/ ;\n" +
328 "스칼라 bmult 수요 승수 /1/; \n" +
329 " \n" +
330 "매개변수 c(i,j) 운송 비용(케이스당 수천 달러); \n" +
331 " \n" +
332 " c(i,j) = f * d(i,j) / 1000 ; \n" +
333 " \n" +
334 "변수 \n" +
335 " 케이스의 x(i,j) 배송 수량 \n" +
336 " z 총 운송 비용(단위: 수천 달러) ; \n" +
337 " \n" +
338 "양수 변수 x ; \n" +
339 " \n" +
340 "방정식 \n" +
341 " 비용 정의 목적 함수 \n" +
342 " 공급(i) 공장 i의 공급 제한 준수 \n" +
343 " 수요(j)는 시장 j의 수요를 충족합니다. \n" +
344 " \n" +
345 "비용 .. z =e= sum((i,j), c(i,j)*x(i,j)) ; \n" +
346 " \n" +
347 "공급(i) .. 합계(j, x(i,j)) =l= a(i) ; \n" +
348 " \n" +
349 "수요(j) .. sum(i, x(i,j)) =g= bmult*b(j) ; \n" +
350 " \n" +
351 "모델 전송 /all/ ; \n" +
352 " \n";
353
354}
GAMSVariable addVariable(문자열 식별자, int 차원, GAMSGlobals.VarType varType)
GAMSParameter getParameter(문자열 식별자)
GAMSSet addSet(문자열 식별자, 정수 차원)
GAMSParameter addParameter(문자열 식별자, 정수 차원)
GAMSSymbol<?> getSymbol(문자열 식별자)
GAMSSet getSet(문자열 식별자)
크레이지 슬롯데이터베이스 OutDB()
크레이지 슬롯데이터베이스 SyncDB()
void instantiate(String modelDefinition, GAMSModifier ... modifiers)
void setSystemDirectory(문자열 디렉터리)
void setWorkingDirectory(문자열 디렉터리)
GAMSJob addJobFromString(문자열 소스)
크레이지 슬롯데이터베이스 addDatabase()
이 예는 크레이지 슬롯 Java API 및 크레이지 슬롯 [trns...를 사용하여 GUSS 접근 방식을 구현하는 방법을 보여줍니다.