로드 중...
검색 중...
일치하는 항목 없음
transport9.cpp
이 파일의 문서로 이동하세요.
1
26#include <벡터>
27#include "슬롯 무료체험h"
28#include <iostream>
29
30네임스페이스 사용표준;
31네임스페이스 사용게임;
32
33#정의된 경우(__unix__) || 정의됨(__linux__) || 정의됨(__APPLE__)
34
39int 메인()
40{
41cout <<"---------- 수송 9 ------------"<< endl;
42cout <<"Transport 9는 Microsoft Windows 전용 예입니다."<< endl;
43 반환0;
44}
45
46#else
47
48#include <QCore애플리케이션>
49#include <QtSql>
50
52문자열 getModelText()
53{
54 반환 " 세트 \n"
55 "나는 식물을 통조림으로 만들고 있습니다 \n"
56 " j 시장 \n"
57 " \n"
58 " 매개변수 \n"
59 " a(i) 경우에 따라 공장 i의 용량 \n"
60 " b(j) 경우의 시장 j 수요 \n"
61 " d(i,j) 거리(천 마일 단위) \n"
62 " 스칼라 f 운임(1,000 마일당 케이스당 달러 단위) /90/; \n"
63 " \n"
64 "$if가 설정되지 않은 경우 gdxincname $abort '제공된 데이터 파일에 대한 포함 파일 이름 없음' \n"
65 "$gdxin %gdxincname% \n"
66 "$load i j a b d \n"
67 "$gdxin \n"
68 " \n"
69 " 매개변수 c(i,j) 운송 비용(케이스당 수천 달러) ; \n"
70 " \n"
71 " c(i,j) = f * d(i,j) / 1000 ; \n"
72 " \n"
73 " 변수 \n"
74 " 케이스의 x(i,j) 배송 수량 \n"
75 " z 총 운송 비용(단위: 수천 달러) ; \n"
76 " \n"
77 " 양수 변수 x ; \n"
78 " \n"
79 " 방정식 \n"
80 " 비용 정의 목적 함수 \n"
81 " 공급(i) 공장 i의 공급 제한 준수 \n"
82 " 수요(j)는 시장 j의 수요를 충족합니다. \n"
83 " \n"
84 " 비용 .. z =e= sum((i,j), c(i,j)*x(i,j)) ; \n"
85 " \n"
86 " 공급(i) .. sum(j, x(i,j)) =l= a(i) ; \n"
87 " \n"
88 " 수요(j) .. sum(i, x(i,j)) =g= b(j) ; \n"
89 " \n"
90 " 모델 전송 /all/ ; \n"
91 " \n"
92 " z를 최소화하는 lp를 사용하여 전송 문제를 해결합니다. \n"
93 " \n"
94 " x.l, x.m 표시 ; \n"
95 " \n";
96}
97
99공허 readSet(QSqlDatabase sqlDb,슬롯 무료체험데이터베이스db,문자열strAccessSelect,문자열세트이름,intsetDim,문자열setExp ="")
100{
101QSqlQuery 쿼리(sqlDb);
102 if(!query.exec(strAccessSelect.c_str()))
103{
104cout <<"'세트에서 쿼리 실행 중 오류 발생'"<< 세트이름 <<"'"<< endl;
105cout << query.lastError().text().toStdString() << endl;
106출구(1);
107}
108 if(query.size() && (query.record().count() != setDim))
109{
110cout <<"select 문의 필드 수가 setDim과 일치하지 않습니다"<< endl;
111출구(1);
112}
113
114 GAMSSeti = DB.추가세트(setName, setDim, setExp);
115벡터<string> 키 = 벡터<string>(setDim);
116
117 그동안(query.next())
118{
119 for (intidx = 0; idx < setDim; idx++)
120keys[idx] = query.value(idx).toString().toStdString();
121i.추가기록(키);
122}
123}
124
126공허 readParameter(QSqlDatabase sqlDb,슬롯 무료체험데이터베이스db,문자열strAccessSelect,문자열par이름,intparDim,문자열parExp ="")
127{
128QSqlQuery 쿼리(sqlDb);
129 if(!query.exec(strAccessSelect.c_str()))
130{
131cout <<"매개변수 '"에 대한 쿼리 실행 중 오류 발생<< par이름 <<"'"<< endl;
132cout << query.lastError().text().toStdString() << endl;
133출구(1);
134}
135 if(query.size() && (query.record().count() != parDim+1))
136{
137cout <<"select 문의 필드 수가 parDim과 일치하지 않습니다"<< endl;
138출구(1);
139}
140
141 슬롯 무료체험매개변수a = DB.addParameter(parName, parDim, parExp);
142벡터<문자열> 키 = 벡터<문자열>(parDim);
143
144 그동안(query.next())
145{
146 for (intidx = 0; idx < parDim; idx++)
147keys[idx] = query.value(idx).toString().toStdString();
148a.추가기록(키).세트값(query.value(parDim).toDouble());
149}
150}
151
154{
156
157QSqlDatabase sqlDb = QSqlDatabase::addDatabase("QODBC", "readConnection");
158
159QString strAccessConn = ("드라이버=Microsoft Access Driver(*.mdb, *.accdb);DSN='';DBQ="+ ws.시스템디렉토리() \
160+ cPathSep +"api파일"+ cPathSep +"데이터"+ cPathSep +"transport.accdb").c_str();
161sqlDb.setDatabaseName(strAccessConn);
162
163 if(sqlDb.open())
164{
165 // 슬롯 무료체험 세트 읽기
166 readSet(sqlDb, DB,"식물에서 식물을 선택하세요", "나", 1,"통조림 공장");
167 readSet(sqlDb, DB,"시장에서 시장 선택", "j", 1,"시장");
168
169 // 슬롯 무료체험 매개변수 읽기
170 readParameter(sqlDb, DB,"공장 선택,공장에서 생산 능력", "a", 1,"케이스에 있는 식물 i의 용량");
171 readParameter(sqlDb, DB,"시장 선택,시장에서 수요", "b", 1,"경우에 따라 시장 j의 수요");
172 readParameter(sqlDb, DB,"공장,시장,거리 FROM 거리 선택", "d", 2,"수천 마일 단위의 거리");
173sqlDb.close();
174}
175 그밖에
176{
177cout <<"오류: 데이터베이스 연결 생성에 실패했습니다."<< sqlDb.lastError().text().toStdString() << endl;
178출구(1);
179}
180 반환db;
181}
182
184무효 writeVariable(QSqlDatabase sqlDb,슬롯 무료체험데이터베이스db,문자열varName, 벡터<string> 도메인)
185{
186 슬롯 무료체험변수var = db.get변수(varName);
187 if(domains.size() !=static_cast<size_t>(변형.어두움()))
188{
189cout <<"열 이름의 수가 변수의 차원과 일치하지 않습니다."<< endl;
190출구(1);
191}
192
193 // 이미 존재하는 경우 varName 테이블 삭제
194QSqlQuery 쿼리(sqlDb);
195query.exec(("드롭 테이블 "+ varName).c_str());
196
197 문자열queryStr ="테이블 생성"+ varName +"(";
198 for (문자열dom : 도메인)
199queryStr += dom +" varchar(64), ";
200queryStr +="레벨 더블)";
201
202query.exec(queryStr.c_str());
203
204 for (GAMSVariableRecordrec : var)
205{
206queryStr =""에 삽입하세요+ varName +"(";
207 for (문자열dom : 도메인)
208queryStr += dom +", ";
209queryStr +="lvl) 값 (";
210 for (문자열키 : rec.keys())
211queryStr +="'"+ 키 +"', ";
212queryStr += std::to_string(rec.level()) +")";
213 if(!query.exec(queryStr.c_str()))
214{
215cout <<"오류: 데이터베이스에 변수를 쓰지 못했습니다"<< endl;
216cout << sqlDb.lastError().text().toStdString() << endl;
217출구(1);
218}
219}
220}
221
224{
225 // 데이터베이스에 연결
226QSqlDatabase sqlDb = QSqlDatabase::addDatabase("QODBC", "writeConnection");
227
228QString strAccessConn = ("드라이버=Microsoft Access 드라이버(*.mdb, *.accdb);DSN='';DBQ="+ ws.시스템디렉토리() \
229+ cPathSep +"api파일"+ cPathSep +"데이터"+ cPathSep +"transport.accdb").c_str();
230sqlDb.setDatabaseName(strAccessConn);
231
232 if(sqlDb.open())
233{
234 // 변수 x의 수준 쓰기
235벡터<string> 도메인"나", "j"};
236 writeVariable(sqlDb, DB,"x", 도메인);
237sqlDb.close();
238}
239 그밖에
240{
241cout <<"오류: 데이터베이스 연결 생성에 실패했습니다."<< sqlDb.lastError().text().toStdString() << endl;
242출구(1);
243}
244}
245
251int 메인(intargc,문자* 인수[])
252{
253cout <<"---------- 수송 9 ------------"<< endl;
254
255
256 시도해 보세요{
257QCoreApplication 앱(argc, argv);
258 GAMSWorkspaceInfowsInfo;
259 if(인수 > 1)
260wsInfo.setSystemDirectory(argv[1]);
262
263 // Access에서 읽어 GAMSDatabase를 채웁니다.
265
266 // 작업 실행
269선택.setDefine("gdxincname", DB.이름());
270선택.setAllModelTypes("익스프레스");
271t9.실행(선택, DB);
272 for (GAMSVariableRecordrec : t9.outDB().get변수("x"))
273cout <<"x("<< Rec.key(0) <<","<< Rec.key(1) <<"):"<<" 레벨="<< Rec.level() <<" 한계="
274<< rec.marginal() << endl;
275 // 결과를 Access 파일에 기록
276 writeToAccess(ws, t9.outDB());
277
278}잡기 (슬롯 무료체험예외&ex)
279cout <<"슬롯 무료체험예외 발생: "<< ex.what() << endl;
280}잡기(예외 &ex)
281cout << ex.what() << endl;
282}
283
284 반환0;
285}
286#endif
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="")
GAMSVariable getVariable(const std::string &name)
슬롯 무료체험데이터베이스 outDB()
void setAllModelTypes(const std::string &solver)
void setDefine(const std::string &key, const std::string &value)
GAMSParameterRecord addRecord(const std::벡터< std::string > &keys)
GAMSSetRecord addRecord(const std::벡터< std::string > &keys)
void setSystemDirectory(const std::string &systemDir)
std::string systemDirectory() const
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[])
void writeToAccess(GAMSWorkspace ws, GAMSDatabase db)
MS Access에 GAMSDatabase를 작성합니다.
void readSet(QSqlDatabase sqlDb, GAMSDatabase db, string strAccessSelect, string setName, int setDim, string setExp="")
MS Access에서 GAMSSet을 읽습니다.
void readParameter(QSqlDatabase sqlDb, GAMSDatabase db, string strAccessSelect, string parName, int parDim, string parExp="")
MS Access에서 GAMSParameter를 읽습니다.
void writeVariable(QSqlDatabase sqlDb, GAMSDatabase db, 문자열 varName, 벡터< 문자열 > 도메인)
MS Access에 GAMSVariable을 쓰십시오.
string getModelText()
모델을 문자열로 가져옵니다.
GAMSDatabase readFromAccess(GAMSWorkspace ws)
MS Access에서 GAMSDatabase로 데이터를 읽습니다.