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

max.cc

00001 #include<scil/scil.h>
00002 #include<scil/constraints/max.h>
00003 
00004 #include<iostream>
00005 #include<fstream>
00006 #include<string>
00007 #include<cstdlib>
00008 
00009 #define INPATH ""
00010 
00011 using std::cout;
00012 using std::cerr;
00013 using std::endl;
00014 using std::ifstream;
00015 
00016 using namespace SCIL;
00017 
00018 int main(int argc, char** argv)
00019 {
00020 
00021    //initialize the ILP
00022    ILP_Problem IP(Optsense_Min);
00023    var_map<int> VM1;
00024    var_map<int> VM2;
00025    std::map<var, double> CF1;
00026    std::map<var, double> CF2;
00027    double G1[3] = {2., -3., 3.};
00028    double G2[4] = {-1., 3., 1., -5.};
00029 
00030    var v = IP.add_variable(1., 0, 17, Vartype_Integer);
00031    var w = IP.add_variable(1., 0, 17, Vartype_Integer);
00032 
00033    for( int i = 0; i < 3; i++) {
00034       VM1[i]=IP.add_variable(G1[i], 0, 10, Vartype_Integer);
00035       CF1[VM1[i]] = 1.;
00036    }
00037    for( int i = 0; i < 4; i++) {
00038       VM2[i]=IP.add_variable(G2[i], 0, 10, Vartype_Integer);
00039       CF2[VM2[i]] = 1.;
00040    }
00041    VM2[4] = VM1[1];
00042    CF2[VM2[4]] = 1.;
00043 
00044    row r;
00045    r += VM1[0];
00046    r += VM1[1];
00047    IP.add_basic_constraint(r>=14.);
00048 
00049    //add the symbolic constraints
00050    IP.add_sym_constraint(new MAX(v, VM1, CF1, 3));
00051    IP.add_sym_constraint(new MAX(w, VM2, CF2, 5));
00052 
00053    //solve the problem
00054    IP.optimize();
00055 
00056    //output the solution
00057    solution sol =  IP.get_solution();
00058    double sum = 0.;
00059 
00060    for( int i = 0; i < 3; i++)
00061       cout << "x" << i << ": " << sol.value(VM1[i]) << endl;
00062    for( int i = 0; i < 4; i++)
00063       cout << "x" << i << ": " << sol.value(VM2[i]) << endl;
00064    cout << "v: " << sol.value(v) << endl;
00065    cout << "w: " << sol.value(w) << endl;
00066 
00067    return 0;
00068 }
00069 
Generated on Mon Mar 28 22:03:48 2011 for SCIL by  doxygen 1.6.3