00001 #include<scil/scil.h>
00002 #include<scil/constraints/atour.h>
00003 #include<scil/constraints/path.h>
00004 #include<boost/foreach.hpp>
00005 #include<boost/graph/iteration_macros.hpp>
00006 #include<fstream>
00007
00008 using namespace SCIL;
00009 using namespace boost;
00010
00011 typedef boost::adjacency_list<vecS,vecS,bidirectionalS,no_property,property<edge_weight_t,int> > Graph;
00012 typedef boost::graph_traits<Graph>::vertex_descriptor vertex_descriptor;
00013 typedef boost::graph_traits<Graph>::edge_descriptor edge_descriptor;
00014 typedef boost::graph_traits<Graph>::edge_iterator edge_iter;
00015
00016
00017 typedef std::pair<vertex_descriptor,vertex_descriptor> prec;
00018
00019 int main(int argc, char **argv) {
00020
00021
00022 const char* fname = (argc > 1) ? argv[1] : "data.sop";
00023 ifstream is(fname);
00024
00025 int i=0, j=0;
00026
00027 Graph G;
00028
00029 vertex_descriptor V[1000];
00030 std::list<prec> PL;
00031
00032 while(j<1000) {
00033 is>>j;
00034 if(j<1000) {
00035 V[i] = add_vertex(G);
00036 i++;
00037 }
00038 };
00039 is>>j;
00040
00041 for(int s=0; s<i; s++) {
00042 for(int t=0; t<i; t++) {
00043 is>>j;
00044 if(s!=t) {
00045 if((s!=i-1) && (t!=i-1)) {
00046 if(j>=0)
00047 add_edge(V[s],V[t],j,G);
00048 else PL.push_back(prec(V[t], V[s]));
00049 }
00050 if((s==i-1) || (t==i-1))
00051 add_edge(V[s],V[t],0,G);
00052 }
00053 cout<<j<<" ";
00054 };
00055 is>>j;
00056 cout<<endl;
00057 };
00058
00059
00060
00061 ILP_Problem IP(Optsense_Min);
00062
00063 var_map<edge_descriptor> VM, VM1;
00064
00065 property_map<Graph, edge_weight_t>::type w
00066 = get(edge_weight, G);
00067
00068
00069 BGL_FORALL_EDGES(e,G,Graph) {
00070 VM[e]=IP.add_binary_variable(w[e]);
00071 if( (source(e,G)!=V[i-1]) && (target(e,G)!=V[i-1]))
00072 VM1[e]=VM[e];
00073 }
00074
00075
00076
00077 IP.add_sym_constraint(new ATOUR<Graph>(G, VM));
00078
00079
00080 prec p;
00081 std::list< PATH<Graph>* > paths;
00082
00083 BOOST_FOREACH(p, PL) {
00084 IP.add_sym_constraint(new PATH<Graph>(G, p.first, p.second, VM1));
00085 };
00086
00087
00088
00089 IP.optimize();
00090
00091 BGL_FORALL_EDGES(e,G,Graph)
00092 if(IP.get_solution(VM[e])==1)
00093 cout << source(e,G) << " " << target(e,G) << " edge\n";
00094
00095 };
00096