Main Page   Class Hierarchy   Compound List   File List   Contact   Download   Symbolic Constraints   Examples  

production.c

00001 #line 2 "production.lw"
00002 #include<scil/scil.h>
00003 #include<scil/constraints/flow.h>
00004 //#include<scil/constraints/cp_knapsack.h>
00005 
00006 using namespace SCIL;
00007 using namespace LEDA;
00008 
00009 #define NI 5
00010 #define NF 10
00011 #define NC 5
00012 
00013 class production_heuristic : public primal_heuristic {
00014   public:
00015 
00016   int heuristic(subproblem& S) {
00017     cout<<"hier\n";
00018     return 0;
00019   }
00020 };
00021 
00022 int main() {
00023 
00024   // Define Input
00025 
00026   int W[NI]={ 7,8,9,10,12 };
00027   int Cap[NF]={ 40, 45, 49, 53, 57, 63, 65, 71, 71, 73 };
00028   int D[NI][NC] = { { 1, 0, 0, 2, 1 },
00029                     { 2, 2, 2, 0, 0 },
00030                     { 0, 1, 1, 2, 1 },
00031                     { 0, 1, 0, 0, 1 },
00032                     { 1, 1, 0, 0, 2 } };
00033   double OC[NF];
00034 
00035   node CN[NC];
00036   node FN[NF];
00037 
00038   double x;
00039   random_source RS;
00040   RS.set_seed(99);
00041   for(int i=0; i<NF; i++) {
00042     RS>>x;
00043     OC[i]=100*x;
00044   }
00045 
00046   graph G;
00047   for(int i=0; i<NF; i++) FN[i]=G.new_node();
00048   for(int i=0; i<NC; i++) CN[i]=G.new_node();
00049 
00050   for(int i=0; i<NF; i++) for(int j=0; j<NC; j++) {
00051     G.new_edge(FN[i], CN[j]);
00052   }
00053 
00054   edge e;
00055   edge_array<double> C(G);
00056   forall_edges(e,G) {
00057     RS>>x;
00058     C[e]=1*x;
00059   }
00060 
00061   // Define Model
00062 
00063   ILP_Problem IP(Optsense_Min);
00064 
00065   array<row_map<node> > NVM(NI); // TODO init
00066   row_map<node> y;
00067   var v;
00068 
00069   node u;
00070 
00071   for(int i=0; i<NF; i++) {
00072     u=FN[i];
00073     for(int j=0; j<NI; j++) {
00074       v=IP.add_variable(0, 0, 10, Vartype_Integer);
00075       NVM[j][u]=v;
00076     }
00077     v=IP.add_variable(OC[i], 0, 1, Vartype_Integer);
00078     y[u]=v;
00079 
00080     row r;
00081     for(int j=0; j<NI; j++) {
00082       r+=W[j]*NVM[j][u]; };
00083     IP.add_basic_constraint(r <= Cap[i]*y[u]);
00084     //IP.add_sym_constraint(new cp_knapsack(r <= Cap[i]*y[u]));
00085   }
00086 
00087   for(int i=0; i<NC; i++) {
00088     for(int j=0; j<NI; j++) {
00089       NVM[j][CN[i]]=D[i][j];
00090     }
00091   }
00092 
00093   row_map<edge> EVM[NI]; // TODO init
00094   for(int i=0; i<NI; i++) {
00095     forall_edges(e, G) {
00096       v=IP.add_variable(C[e], 0, 100, Vartype_Float);
00097       EVM[i][e]=v;
00098     }
00099     IP.add_sym_constraint(new FLOW(G, NVM[i], EVM[i]));
00100   }
00101 
00102   // Solve
00103 
00104   IP.set_primal_heuristic(new production_heuristic());
00105 
00106   IP.optimize();
00107 
00108   // Display Solution
00109 
00110   for(int i=0; i<NF; i++) {
00111     cout<<IP.get_solution(y[FN[i]])<<" solution of facility "<<i<<endl;
00112     if(IP.get_solution(y[FN[i]])>0.5) {
00113       cout<<"It produces\n";
00114       for(int j=0; j<NI; j++) {
00115         cout<<IP.get_solution(NVM[j][FN[i]])<<" Items of item "<<j<<"\n";
00116       }
00117     }
00118   }
00119 
00120   return 0;
00121 }
00122 

Generated on Tue Nov 16 15:18:18 2004 for SCIL by doxygen1.2.16