로드 중...
검색 중...
일치하는 항목 없음
transport12.cpp
이 파일의 문서로 이동하세요.
1
25#include "슬롯 커뮤니티h"
26
27#include <알고리즘>
28#include <iostream>
29
30네임스페이스 사용게임;
31네임스페이스 사용표준;
32
34문자열 getModelText()
35{
36 반환 " 세트 \n"
37 " 나는 식물 통조림 / 시애틀, 샌디에이고 / \n"
38 " j 마켓 / 뉴욕, 시카고, 토피카 / ; \n"
39 " \n"
40 " 매개변수 \n"
41 " \n"
42 " a(i) 경우에 따라 공장 i의 용량 \n"
43 " / 시애틀 350 \n"
44 " 샌디에고 600 / \n"
45 " \n"
46 " b(j) 경우의 시장 j 수요 \n"
47 " / 뉴욕 325 \n"
48 " 시카고 300 \n"
49 " 토피카 275 / ; \n"
50 " \n"
51 " 테이블 d(i,j) 거리(천 마일 단위) \n"
52 " 뉴욕 시카고 토피카 \n"
53 " 시애틀 2.5 1.7 1.8 \n"
54 " 샌디에고 2.5 1.8 1.4 ; \n"
55 " \n"
56 " 스칼라 f 운임(1,000 마일당 케이스당 달러 단위) /90/ ; \n"
57 " 스칼라 bmult 수요 승수 /1/; \n"
58 " \n"
59 " 매개변수 c(i,j) 운송 비용(케이스당 수천 달러) ; \n"
60 " \n"
61 " c(i,j) = f * d(i,j) / 1000 ; \n"
62 " \n"
63 " 변수 \n"
64 " x(i,j) 배송 수량 \n"
65 " z 총 운송 비용(수천 달러) ; \n"
66 " \n"
67 " 양수 변수 x ; \n"
68 " \n"
69 " 방정식 \n"
70 " 비용 정의 목적 함수 \n"
71 " 공급(i) i 공장의 공급 제한 준수 \n"
72 " 수요(j)는 시장 j의 수요를 충족시킵니다. \n"
73 " \n"
74 " 비용 .. z =e= sum((i,j), c(i,j)*x(i,j)) ; \n"
75 " \n"
76 " 공급(i) .. sum(j, x(i,j)) =l= a(i) ; \n"
77 " \n"
78 " 수요(j) .. sum(i, x(i,j)) =g= bmult*b(j) ; \n"
79 " \n"
80 " 모델 전송 /all/ ; \n";
81}
82
84문자열 toLower(const 문자열&str)
85{
86 문자열lstr(str);
87transform(lstr.begin(), lstr.end(), lstr.begin(), ::tolower);
88 반환lstr;
89}
90
92공허 GUSS콜(GAMSSetdict,GAMSModelInstance미,문자열solveStatement
93 , 슬롯 커뮤니티::GAMSOptions* 선택 =nullptr
95, std::ostream* 출력 =nullptr)
96{
97벡터< tuple<GAMSModifier, GAMSParameter> > modifierList;
98
99 if(dict.어두움() != 3)
100 던지다 슬롯 커뮤니티예외("사전은 3차원이어야 합니다");
101
102벡터<문자열> 문자열" ", "시나리오", " "};
103 문자열scenName = 사전.첫 번째 레코드(strs).(0);
104 GAMSSetscenSymbol = 사전.데이터베이스().getSet(scenName);
105
106
107 for (GAMSSetRecordrec : 사전)
108 if (toLower(rec.key(1)) =="시나리오")
109 계속;
110 if (toLower(rec.key(1)) =="매개변수") {
111 intmodifierDim = dict.database().getParameter(rec.key(2)).dim() - scenSymbol.어두움();
112 if(modifierDim < 0)
113 던지기 슬롯 커뮤니티예외("크기"+ Rec.key(2) +"너무 작습니다");
114 자동튜플 = make_tuple(GAMSModifier(mi.syncDb().addParameter(rec.key(0), modifierDim,"")),
115dict.database().getParameter(rec.key(2)));
116modifierList.push_back(tuple);
117
118}그밖에 if((rec.key(1) =="낮은") || (toLower(rec.key(1)) =="상단") || (toLower(rec.key(1)) =="고정됨")) {
119 intmodifierDim = dict.database().getParameter(rec.key(2)).dim() - scenSymbol.어두움();
120 if(modifierDim < 0)
121 던지다 슬롯 커뮤니티예외("크기"+ Rec.key(2) +"너무 작습니다");
122
123 슬롯 커뮤니티변수modifierVar;
124 시도해 보세요{
125modifierVar = 사전.데이터베이스().get변수(rec.key(0));
126}잡기(...) {
127modifierVar = mi.syncDb().추가변수(rec.key(0),modifierDim,GAMSEnum::무료, "");
128}
129
130 if (toLower(rec.key(1)) =="낮은") {
131 자동튜플 = make_tuple(GAMSModifier(modifierVar,GAMSEnum::낮음,
132mi.syncDb().addParameter(rec.key(2), modifierDim,"")),
133dict.database().getParameter(rec.key(2)));
134modifierList.push_back(tuple);
135
136}그밖에 if (toLower(rec.key(1)) =="상단") {
137 자동튜플 = make_tuple(GAMSModifier(modifierVar,GAMSEnum::상위,
138mi.syncDb().addParameter(rec.key(2), modifierDim,"")),
139dict.database().getParameter(rec.key(2)));
140modifierList.push_back(tuple);
141
142}그밖에{// 수정됨
143 자동튜플 = make_tuple(GAMSModifier(modifierVar,GAMSEnum::Fixed,
144mi.syncDb().addParameter(rec.key(2), modifierDim,"")),
145dict.database().getParameter(rec.key(2)));
146modifierList.push_back(tuple);
147}
148}그밖에 if ((toLower(rec.key(1)) =="레벨") || (toLower(rec.key(1)) =="한계")) {
149 // GAMSDatabase에 매개변수가 있는지 확인하세요. 없으면 예외가 발생합니다.
150dict.database().getParameter(rec.key(2));
151}그밖에{
152 던지기 슬롯 커뮤니티예외("UpdateAction을 처리할 수 없습니다."+ Rec.key(1));
153}
154}
155
156벡터<GAMSModifier> mL;
157 for (자동튜플 : modifierList)
158mL.push_back(get<0>(튜플));
159 if(선택)
160mi.인스턴스화(solveStatement, *opt, mL);
161 그밖에
162mi.인스턴스화(solveStatement, mL);
163
164벡터<tuple<GAMSSymbol, GAMSParameter, 문자열>> outList;
165
166 for (GAMSSetRecords : scenSymbol)
167{
168 for (자동tup : modifierList)
169{
171 슬롯 커뮤니티매개변수pscen = get<1>(tup);
172
173 if(!get<0>(tup).dataSymbol().isValid())
174p = get<0>(tup).gamsSymbol();
175 그밖에
176p = get<0>(tup).dataSymbol();
177
178 // SymbolUpdateType=BaseCase 구현됨
179p.지우기();
180
182벡터<문자열> 필터(pscen.어두움());
183 for (inti = 0; 나는 < scenSymbol.어두움(); 나++)
184필터[i] = s.key(i);
185 for (inti = scenSymbol.어두움(); 나는 <pscen.어두움(); 나++)
186필터[i] =" ";
187
188 시도해 보세요{
189rec = pscen.첫 번째 레코드(필터);
191 계속;
192}
193
194 할 것{
195벡터<string> myKeys(p.어두움());
196 for (inti = 0; 나는 <p.어두움(); 나++)
197myKeys[i] = Rec.(scenSymbol.어두움()+i);
198p.추가기록(내키).세트값(추천());
199}그동안(추천이동다음());
200}
201
202mi.해결(GAMSEnum::SymbolUpdateType::BaseCase, *output, miOpt);
203
204 if(outList.size() == 0)
205 for (GAMSSetRecordrec : 사전)
206 if ((toLower(rec.key(1)) =="레벨") || (toLower(rec.key(1)) =="한계")) {
207 자동tuple = make_tuple(mi.syncDb().getSymbol(rec.key(0)),
208말씀.데이터베이스().getParameter(rec.key(2)),
209 toLower(rec.key(1)));
210outList.push_back(tuple);
211}
212
213 for(tuple<GAMSSymbol, GAMSParameter, string> tup : outList)
214 GAMSSymbolmySym = get<0>(tup);
215벡터<string> myKeys;
216 for (inti = 0; 나는 < scenSymbol.어두움(); 나++)
217myKeys.push_back(s.key(i));
218
219 if((get<2>(tup) =="레벨") && (mySym.유형() ==GAMSEnum::SymTypeVar)) {
221 for (inti = 0; i < static_cast<int>(rec.keys().size()); 나++)
222myKeys[scenSymbol.어두움() + i] = s.key(i);
223get<1>(tup).addRecord(myKeys).setValue(rec.level());
224}
225}그밖에 if((get<2>(tup) =="레벨") && (mySym.유형() ==GAMSEnum::SymTypeEqu)) {
226 for (GAMSequationRecord기록 :GAMSequation(mySym))
227 for (inti = 0; i < static_cast<int>(rec.keys().size()); 나++)
228myKeys[scenSymbol.어두움() + i] = s.key(i);
229get<1>(tup).addRecord(myKeys).setValue(rec.level());
230}
231}그밖에 if((get<2>(tup) =="한계") && (mySym.유형() ==GAMSEnum::SymTypeVar)) {
233 for (inti = 0; i < static_cast<int>(rec.keys().size()); 나++)
234myKeys[scenSymbol.어두움() + i] = s.key(i);
235get<1>(tup).addRecord(myKeys).setValue(rec.marginal());
236}
237}그밖에 if((get<2>(tup) =="한계") && (mySym.유형() ==GAMSEnum::SymTypeEqu)) {
238 for (GAMSequationRecord기록 :GAMSequation(mySym))
239 for (inti = 0; i < static_cast<int>(rec.keys().size()); 나++)
240myKeys[scenSymbol.어두움() + i] = s.key(i);
241get<1>(tup).addRecord(myKeys).setValue(rec.marginal());
242}
243}
244}
245}
246}
247
253int 메인(intargc,문자* 인수[])
254{
255cout <<"---------- 수송 12 ------------"<< endl;
256
257 시도해 보세요{
258 GAMSWorkspaceInfowsInfo;
259 if(인수 > 1)
260wsInfo.setSystemDirectory(argv[1]);
263
264 // GAMSJob을 실행하여 GAMSCheckpoint 초기화
266t12.실행(cp);
267
268 // GAMSModelInstance를 생성하고 다른 스칼라 bmult를 사용하여 여러 번 해결
270
271 더블bmultlist[] 0.6, 0.7, 0.8, 0.9, 1.0, 1.1, 1.2, 1.3 ;
272
274
275 GAMSSetscen = db.추가세트("장면", 1,"");
276 슬롯 커뮤니티매개변수bmult = db.addParameter("b다중 목록", "", 장면);
277 슬롯 커뮤니티매개변수zscen = db.addParameter("zscen", "", 장면);
278
279 inti = 0;
280 for (더블b : bmultlist)
281b다중.추가기록("들"+ to_string(i)).세트값(b);
282장면.추가기록("들"+ to_string(i++));
283}
284
285 GAMSSetdict = db.추가세트("dict",3,"");
286dict.추가기록(장면.이름(), "시나리오", "");
287dict.추가기록("bmult", "매개변수", bmult.이름());
288dict.추가기록("z", "레벨", zscen.이름());
289
290
291 GUSS콜(dict, mi,"운송은 lp min z를 사용합니다");
292
293 (GAMSParameterRecordrec : db.getParameter(zscen.이름()))
294cout << rec.key(0) <<" obj: "<< Rec.value() << endl;
295
298
299 GAMSSetscen2 = db2.추가세트("장면", 1,"");
300 슬롯 커뮤니티매개변수zscen2 = db2.추가매개변수("zscen", "", 장면2);
302
303 for (intj = 0; j<4; j++)
304 for (GAMSSetRecordirec : t12.outDB().getSet("나"))
305 for (GAMSSetRecordjrec : t12.outDB().getSet("j"))
306xup.추가기록("들"+ to_string(j), irec.key(0), jrec.key(0)).세트값(j+1);
307scen2.추가기록("들"+ to_string(j));
308}
309
310 GAMSSetdict2 = db2.추가세트("dict", 3,"");
311dict2.추가기록(scen2.이름(), "시나리오", "");
312dict2.추가기록("x", "낮은", xup.이름());
313dict2.추가기록("z", "레벨", zscen2.이름());
314
315 GUSS콜(dict2, mi2,"교통수단은 lp min z를 사용합니다");
316
317 for (GAMSParameterRecordrec : db2.getParameter(zscen2.이름()))
318cout << rec.key(0) <<" obj: "<< Rec.value() << endl;
319
320}잡기 (슬롯 커뮤니티예외&ex)
321cout <<"슬롯 커뮤니티예외 발생: "<< ex.what() << endl;
322}잡기(예외 &ex)
323cout << ex.what() << endl;
324}
325
326 반환0;
327}
GAMSModelInstance addModelInstance(const std::string &modelInstanceName="")
GAMSVariable addVariable(const std::string &name, const int 차원, const GAMSEnum::VarType varType, const std::string &explanatoryText="")
GAMSSet addSet(const std::string &name, const int 차원, const std::string &explanatoryText="", GAMSEnum::SetType setType=GAMSEnum::SetType::Multi)
GAMSParameter addParameter(const std::string &name, const int 차원, const std::string &explanatoryText="")
GAMSSymbol getSymbol(const std::string &name)
GAMSSet getSet(const std::string &name)
GAMSParameter getParameter(const std::string &name)
GAMSVariable getVariable(const std::string &name)
슬롯 커뮤니티데이터베이스 outDB()
void 인스턴스화(const std::string &modelDefinition, const 슬롯 커뮤니티::GAMSOptions &options, const std::Vector< 슬롯 커뮤니티::GAMSModifier > &modifiers= )
voidsolv(GAMSEnum::SymbolUpdateType updateType, std::ostream &output, const GAMSModelInstanceOpt &miOpt)
슬롯 커뮤니티데이터베이스 syncDb()
GAMSParameterRecord firstRecord(const std::벡터< std::string > &slice)
GAMSParameterRecord addRecord(const std::벡터< std::string > &keys)
GAMSSetRecord firstRecord(const std::벡터< std::string > &slice)
GAMSSetRecord addRecord(const std::벡터< std::string > &keys)
std::string 키(int 인덱스)
std::string & name() const
슬롯 커뮤니티::슬롯 커뮤니티데이터베이스 및 데이터베이스() const
GAMSEnum::SymbolType type() const
void setSystemDirectory(const std::string &systemDir)
GAMSJob addJobFromString(const std::string &gamsSource, const std::string &jobName="")
GAMSDatabase addDatabase(const std::string &databaseName="", const std::string &inModelName="")
GAMSCheckpoint addCheckpoint(const std::string &checkpointName="")
void GUSSCall(GAMSSet dict, GAMSModelInstance mi, stringsolvStatement, 슬롯 커뮤니티::GAMSOptions *opt=nullptr, 슬롯 커뮤니티::GAMSModelInstanceOpt miOpt=슬롯 커뮤니티::GAMSModelInstanceOpt(), std::ostream *output=nullptr)
GUSS를 사용하여 다양한 시나리오에서 모델을 해결합니다.
int main(int argc, char *argv[])
string getModelText()
모델을 문자열로 가져옵니다.
string toLower(const string &str)
문자열을 소문자로 변환합니다.