로드 중...
검색 중...
일치하는 항목 없음
warehouse.cpp
이 파일의 문서로 이동하세요.
1
25#include <iostream>
26#include <fstream>
27#include <뮤텍스>
28#include <스레드>
29#include "슬롯 커뮤니티h"
30
31네임스페이스 사용게임;
32네임스페이스 사용표준;
33
34정적 int상태;
35정적 문자열statusString;
36
38문자열 getModelText()
39{
40 반환 "$title Warehouse.gms \n"
41 " \n"
42 "$eolcom // \n"
43 "$SetDDList 창고 저장소 고정 분리 // 허용 가능한 정의 \n"
44 "$창고를 설정하지 않은 경우 $창고 10을 설정 \n"
45 "$설정되지 않은 상점 $set 상점 50 \n"
46 "$설정되지 않은 경우 고정 $set 고정 20 \n"
47 "$if set not set disaggregate $set disaggregate 1 // 더 엄격한 bigM 제약 조건에 대한 표시 \n"
48 "$ife %store%<=%warehouse% $abort 매장 수 증가 (>%warehouse) \n"
49 " \n"
50 "응답 응답 코드 설정 / 0 일반 \n"
51 " 1 라이센스 오류 \n"
52 " 2 해결책 없음 \n"
53 " 3 기타 오류 / \n"
54 " 아르(res) / 3 /; \n"
55 " \n"
56 "창고 설정 /w1*w%warehouse% / \n"
57 " 저장 /s1*s%store% / \n"
58 "별칭 (창고,w), (상점,s); \n"
59 "스칼라 \n"
60 " 창고 개설을 위한 고정 고정 비용 / %fixed% / \n"
61 "매개변수 \n"
62 " 용량(WareHouse) \n"
63 " 공급 비용(상점,창고); \n"
64 " \n"
65 "$eval storeDIVwarehouse trunc(카드(스토어)/카드(창고)) \n"
66 "용량(w) = %storeDIVwarehouse% + mod(ord(w),%storeDIVwarehouse%); \n"
67 "공급 비용(s,w) = 1+mod(ord(s)+10*ord(w), 100); \n"
68 " \n"
69 "변수 \n"
70 " 열기(창고) \n"
71 " 공급(상점,창고) \n"
72 "obj; \n"
73 "이진 변수 열기, 공급; \n"
74 " \n"
75 "방정식 \n"
76 " defobj \n"
77 " 하나의 창고 \n"
78 " defopen(w); \n"
79 " \n"
80 "defobj.. obj =e= 합계(w, 고정*개방(w)) + 합계((w,s), 공급 비용(s,w)*공급(s,w)); \n"
81 " \n"
82 "하나의 창고.. 합계(w, 공급(들,w)) =e= 1; \n"
83 " \n"
84 "defopen(w).. sum(s, 공급(s,w)) =l= open(w)*capacity(w); \n"
85 " \n"
86 "$ifthen %disaggregate%==1 \n"
87 "방정식 \n"
88 " defopen2(s,w); \n"
89 "defopen2(s,w).. 공급(s,w) =l= 개방(w); \n"
90 "$endif \n"
91 " \n"
92 "모델 분포 /all/; \n"
93 "Mip를 사용하여 최소 obj 분포를 해결합니다. \n"
94 " \n"
95 "$macro setResult(n) 옵션clear=ares; ares(n) = yes; \n"
96 "if (distrib.modelstat=%ModelStat.LicensingProblem% 또는 \n"
97 " distrib.solvestat=%Solvestat.LicensingProblems%, \n"
98 " setResult('1'); \n"
99 " '라이센스 오류'를 중단합니다. \n"
100 "); \n"
101 "if (distrib.solvestat<>%SolveStat.NormalCompletion% 또는 \n"
102 " distrib.modelstat<>%ModelStat.Optimal% 및 \n"
103 " distrib.modelstat<>%ModelStat.IntegerSolution%, \n"
104 " setResult('2'); \n"
105 " '해결 방법 없음'을 중단합니다. \n"
106 "); \n"
107 "setResult('0'); \n";
108}
109
110무효 solveWarehouse(슬롯 커뮤니티작업공간* 으음,int창고 수,슬롯 커뮤니티데이터베이스* resultDB, 뮤텍스* dbMutex)
111{
113 시도{
114 // GAMSOptions를 인스턴스화하고 일부 스칼라 정의
116gmsOpt.setAllModelTypes("복합체");
117gmsOpt.setDefine("창고", to_string(numberOfWarehouses));
118gmsOpt.setDefine("상점", "65");
119gmsOpt.setDefine("고정됨", "22");
120gmsOpt.setDefine("분리", "0");
121gmsOpt.setOptCR(0.0);
122
123 // 문자열에서 GAMSJob을 생성하고 결과 데이터베이스에 결과를 씁니다.
124gmsJ.실행(gmsOpt);
125
126 // 데이터베이스 쓰기 작업을 잠가야 함
127{
128lock_guard<mutex> dbLock(*dbMutex);
129결과DB->getParameter("objrep").추가기록(to_string(numberOfWarehouses)).세트값(gmsJ.outDB().get변수("obj").findRecord().레벨());
130}
131
132 for(GAMSVariableRecordsupplyRec : gmsJ.outDB().get변수("공급"))
133{
134 if(supplyRec.level() > 0.5)
135{
136lock_guard<mutex> dbLock(*dbMutex);
137결과DB->getSet("공급지도").추가기록(to_string(numberOfWarehouses), 공급Rec.key(0), 공급Rec.key(1));
138}
139}
140}
141 잡기(GAMSExceptionExecution& 전자)
142{
143 if(예.rc() ==GAMSEnum::ExecutionError)
144{
145lock_guard<mutex> dbLock(*dbMutex);
146statusString = gmsJ.outDB().getSet("res").findRecord(gmsJ.outDB().getSet("아레스").첫 번째 레코드().(0)).텍스트();
147}
148{
149lock_guard<mutex> dbLock(*dbMutex);
150상태 = e.rc();
151}
152}
153 잡기 (슬롯 커뮤니티예외& 전자)
154{
155cout << e.what() << endl;
156lock_guard<mutex> dbLock(*dbMutex);
157상태 = -1;
158}
159 잡기(예외&e)
160{
161cout << e.what() << endl;
162lock_guard<mutex> dbLock(*dbMutex);
163상태 = -2;
164}
165}
166
175int 메인(intargc,문자* argv[])
176{
177cout <<"------------ 창고 ------------"<< endl;
178
179 시도해 보세요{
180 GAMSWorkspaceInfowsInfo;
181 if(인수 > 1)
182wsInfo.setSystemDirectory(argv[1]);
184
185 // 결과에 대한 GAMSDatabase 생성
187
188결과DB.addParameter("objrep", 1,"목표 값");
189결과DB.추가세트("공급 지도", 3,"레벨에 따른 공급 연결");
190 // 여러 병렬 작업 실행
191뮤텍스 dbMutex;
192벡터<스레드> v;
193 for(intnr창고=10; nr창고<22; nr창고++)
194v.emplace_back([&ws, nrWarehouses, &resultDB, &dbMutex]solveWarehouse(&ws, nrWarehouses, &resultDB, &dbMutex););
195 for (자동& t : v)
196t.join();
197 if(상태 > 0)
198 던지기 GAMSExceptionExecution("슬롯 커뮤니티 실행 중 오류: " + GAMSEnum::text((GAMSEnum::GAMSExitCode) 상태) +" "+ statusString, 상태, &ws);
199 그밖에 if(상태 == -1)
200 던지기 슬롯 커뮤니티예외("슬롯 커뮤니티 API 오류");
201 그밖에 if(상태 == -2)
202 던지기예외();
203 // 결과 데이터베이스를 GDX 파일로 내보내기
204결과DB.do내보내기("\\tmp\\resultCpp.gdx");
205}잡기 (슬롯 커뮤니티예외&ex)
206cout <<"슬롯 커뮤니티예외 발생: "<< ex.what() << endl;
207}잡기(예외 &ex)
208cout << ex.what() << endl;
209}
210 반환상태;
211}
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="")
void doExport(const std::string &filePath="")
GAMSSet getSet(const std::string &name)
GAMSParameter getParameter(const std::string &name)
GAMSVariable getVariable(const std::string &name)
정적 std::string 텍스트(GAMSEnum::SymbolType 유형)
슬롯 커뮤니티데이터베이스 outDB()
void setAllModelTypes(const std::string &solver)
void setOptCR(const double value)
void setDefine(const std::string &key, const std::string &value)
GAMSParameterRecord addRecord(const std::벡터< std::string > &keys)
GAMSSetRecord findRecord(const std::벡터< std::string > &keys)
GAMSSetRecord firstRecord(const std::벡터< std::string > &slice)
GAMSSetRecord addRecord(const std::벡터< std::string > &keys)
std::string 키(int 인덱스)
GAMSVariableRecord findRecord(const std::벡터< std::string > &keys)
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="")
int main(int argc, char *argv[])
voidsolvWarehouse(GAMSWorkspace *ws, int numberOfWarehouses, GAMSDatabase *resultDB, mutex *dbMutex)
string getModelText()
모델을 문자열로 가져옵니다.