로드 중...
검색 중...
일치하는 항목 없음
transportGDX.cpp
이 파일의 문서로 이동하세요.
1
25#include "슬롯 나라h"
26#include <iostream>
27#include <fstream>
28#include <벡터>
29#include <지도>
30#include <cstdlib>
31
32네임스페이스 사용게임;
33네임스페이스 사용표준;
34
35
42int 메인(intargc,문자* argv[])
43{
44cout <<"---------- GDX 전송 ------------"<< endl;
45
46 시도해 보세요{
48 if(인수 > 1)
49wsInfo.setSystemDirectory(argv[1]);
51
52 // C++ 데이터 구조를 사용하여 일부 데이터 정의
53벡터<string> 식물 =
54 "시애틀", "샌디에이고"
55};
56벡터<문자열> 시장 =
57 "뉴욕", "시카고", "토피카"
58};
59map<string, double> 용량 =
60{"시애틀", 350.0 }, { "샌디에고", 600.0 }
61};
62map<string, double> 수요 =
63{"뉴욕", 325.0 }, { "시카고", 300.0 }, { "토피카", 275.0 }
64};
65맵<튜플<문자열, 문자열>,더블> 거리 =
66make_tuple("시애틀", "뉴욕"), 2.5 },
67make_tuple("시애틀", "시카고"), 1.7 },
68make_tuple("시애틀", "토피카"), 1.8 },
69make_tuple("샌디에고", "뉴욕"), 2.5 },
70make_tuple("샌디에고", "시카고"), 1.8 },
71make_tuple("샌디에고", "토피카"), 1.4 }
72};
73
74 // 새 GAMSDatabase 인스턴스 생성
76
77 // 설명 텍스트 '통조림 식물'과 함께 1차원 세트 'i'를 슬롯 나라데이터베이스에 추가
78 GAMSSeti = db.추가세트("나", 1,"통조림 공장");
79 for (문자열p: 식물)
80i.추가기록(p);
81
82 // 설명 텍스트 'markets'가 포함된 1차원 세트 'j'를 GAMSDatabase에 추가
83 GAMSSetj = db.추가세트("j", 1,"시장");
84 for (문자열m: 시장)
85j.추가기록(m);
86
87 // 도메인 'i'에 매개변수 'a' 추가
88 슬롯 나라매개변수a = DB.addParameter("a", "케이스에 있는 식물 i의 용량", i);
89 for (문자열p: 식물)
90a.추가기록(p).세트값(용량[p]);
91
92 // 도메인 'j'에 매개변수 'b' 추가
93 슬롯 나라매개변수b = DB.addParameter("b", "경우에 따라 시장 j의 수요", j);
94 for (문자열m: 시장)
95b.추가기록(m).setValue(수요[m]);
96
97 // 도메인 'i' 및 'j'가 포함된 매개변수 'd' 추가
98 슬롯 나라매개변수d = DB.addParameter("d", "수천 마일 단위의 거리", i, j);
99 for (자동t : 거리)
100d.추가기록(get<0>(t.first), get<1>(t.first)).세트값(t.초);
101
102 // 스칼라 'f' 추가
103 슬롯 나라매개변수f = db.addParameter("f", "1,000마일당 케이스당 화물(달러)");
104f.추가기록().세트값(90);
105
106 // GAMSDatabase를 GAMSWorkspace의 'workingDirectory'에 있는 'data.gdx' 이름의 GDX 파일로 내보냅니다.
107db.do내보내기("data.gdx");
108
109cout <<"GDX 파일 'data.gdx'의 내용:";
110 문자열명령 ="gdxdump "+ ws.workingDirectory() + cPathSep +"data.gdx";
111 intret = system(command.c_str());
112 if(재개)
113cerr <<"시스템("<< command.c_str() <<")가 "를 반환했습니다.<< ret << endl;
114
115 // 새 GAMSDatabase를 추가하고 방금 생성된 GDX 파일에서 초기화
117
118 // 기호의 데이터를 C++ 데이터 구조로 읽습니다.
119벡터<string> iNew;
120 for(GAMSSetRecordrec:db2.getSet("나"))
121iNew.push_back(rec.key(0));
122
123벡터<string> jNew;
124 for(GAMSSetRecordrec:db2.getSet("j"))
125jNew.push_back(rec.key(0));
126
127map<string, double> aNew;
128 for(GAMSParameterRecordrec:db2.getParameter("a"))
129aNew[rec.key(0)] = rec.value();
130
131map<string, double> bNew;
132 for(GAMSParameterRecordrec:db2.getParameter("b"))
133bNew[rec.key(0)] = Rec.value();
134
135맵<튜플<문자열, 문자열>,더블> d새로;
136 for(GAMSParameterRecordrec:db2.getParameter("d"))
137dNew[make_tuple(rec.key(0), rec.key(1))] = rec.value();
138
139 더블fNew = db2.getParameter("f").첫 번째 레코드().();
140
141cout <<"나:"<< endl;
142 for(문자열s : iNew)
143cout <<" "<< s << endl;
144cout <<"j:"<< endl;
145 for(문자열s : jNew)
146cout <<" "<< s << endl;
147cout <<"a:"<< endl;
148 for (자동rec : aNew)
149cout <<" "<< 우선순위 <<" : "<< Rec.초 << endl;
150cout <<"b:"<< endl;
151 for (자동rec : bNew)
152cout <<" "<< 우선순위 <<" : "<< Rec.초 << endl;
153cout <<"d:"<< endl;
154 for (자동rec : dNew)
155cout <<" "<< get<0>(rec.first) <<", "<< get<1>(rec.first) <<" : "<< Rec.초 << endl;
156cout <<"f:"<< endl;
157cout <<" "<< fNew;
158
159}잡기 (슬롯 나라예외&ex)
160cout <<"슬롯 나라예외 발생: "<< ex.what() << endl;
161}잡기(예외 &ex)
162cout << ex.what() << endl;
163}
164
165 반환0;
166}
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)
void setValue(const double val)
GAMSParameterRecord firstRecord(const std::벡터< std::string > &slice)
GAMSParameterRecord addRecord(const std::벡터< std::string > &keys)
GAMSSetRecord addRecord(const std::벡터< std::string > &keys)
void setSystemDirectory(const std::string &systemDir)
std::string WorkingDirectory() const
GAMSDatabase addDatabase(const std::string &databaseName="", const std::string &inModelName="")
GAMSDatabase addDatabaseFromGDX(const std::string &gdxFileName, const std::string &databaseName, const std::string &inModelName)
int main(int argc, char *argv[])