01: // -------------------------------------------------------------- -*- C++ -*-
02: // File: mulprod_main.cpp
03: // --------------------------------------------------------------------------
04: // Licensed Materials - Property of IBM
05: // 
06: // 5725-A06 5725-A29 5724-Y48 5724-Y49 5724-Y54 5724-Y55 
07: // Copyright IBM Corporation 1998, 2013. All Rights Reserved.
08: //
09: // Note to U.S. Government Users Restricted Rights:
10: // Use, duplication or disclosure restricted by GSA ADP Schedule
11: // Contract with IBM Corp.
12: /////////////////////////////////////////////////////////////////////////////// 
13: 
14: #include <ilopl/iloopl.h>
15: 
16: #include <sstream>
17: 
18: #ifdef ILO_WINDOWS
19: #define DIRSEP "\\"
20: #else
21: #define DIRSEP "/"
22: #endif
23: #ifndef DATADIR
24: #define DATADIR ".." DIRSEP ".."  DIRSEP ".." DIRSEP ".." DIRSEP "opl" DIRSEP
25: #endif
26: 
27: ILOSTLBEGIN
28: 
29: int main(int argc,char* argv[]) {
30:     IloEnv env;
31: 
32: 
33:     int status = 127;
34:     try {
35:         IloInt capFlour = 20; 
36:         IloNum best;
37:         IloNum curr = IloInfinity;
38: 
39:         IloOplRunConfiguration rc0(env,
40:             DATADIR  "mulprod" DIRSEP "mulprod.mod",
41:             DATADIR  "mulprod" DIRSEP "mulprod.dat");
42:         IloOplDataElements dataElements = rc0.getOplModel().makeDataElements();
43: 
44:         do {
45:           best = curr;
46: 
47:           IloOplRunConfiguration rc(rc0.getOplModel().getModelDefinition(),
48:               dataElements);
49: 
50:           rc.getCplex().setOut(env.getNullStream());
51:           rc.getOplModel().generate();
52: 
53:           cout << "Solve with capFlour = " << capFlour << endl;
54:           if ( rc.getCplex().solve() ) {
55:               curr = rc.getCplex().getObjValue();
56:               cout << endl
57:                   << "OBJECTIVE: " << fixed << setprecision(2) << curr
58:                   << endl;
59:               status = 0;
60:           } else {
61:               cout << "No solution!" << endl;
62:               status = 1;
63:           }
64: 
65:           capFlour++;
66:           // Change the value of Capacity["flour"] in dataElements
67:           dataElements.getElement("Capacity").asNumMap().set("flour", capFlour);
68: 
69:           rc.end();
70:         } while ( best != curr && status == 0);
71:     } catch (IloOplException & e) {
72:         cout << "### OPL exception: " << e.getMessage() << endl;
73:     } catch( IloException & e ) {
74:         cout << "### CONCERT exception: ";
75:         e.print(cout);
76:         status = 2;
77:     } catch (...) {
78:         cout << "### UNEXPECTED ERROR ..." << endl;
79:         status = 3;
80:         return status;
81:     }
82: 
83:     env.end();
84: 
85:     cout << endl << "--Press <Enter> to exit--" << endl;
86:     getchar();
87:     
88:     return status;
89: }