00001 #include<scil/scil.h>
00002 #include<scil/constraints/atour.h>
00003 #include<scil/constraints/path.h>
00004
00005 #include<LEDA/tuple.h>
00006 #include<LEDA/stream.h>
00007 #include<fstream.h>
00008
00009 using namespace SCIL;
00010 using namespace LEDA;
00011
00012 typedef two_tuple<node, node> prec;
00013
00014 int main() {
00015
00016
00017
00018 ifstream is("data.sop");
00019
00020 int i=0, j=0;
00021
00022 GRAPH<int, int> G;
00023 node N[1000];
00024 list<prec> PL;
00025
00026 while(j<1000) {
00027 is>>j;
00028 if(j<1000) {
00029 N[i]=G.new_node(i);
00030 i++;
00031 }
00032 };
00033 is>>j;
00034
00035 for(int s=0; s<i; s++) {
00036 for(int t=0; t<i; t++) {
00037 is>>j;
00038 if(s!=t) {
00039 if((s!=i-1) && (t!=i-1)) {
00040 if(j>=0)
00041 G.new_edge(N[s],N[t], j);
00042 else PL.append(prec(N[t], N[s]));
00043 }
00044 if((s==i-1) || (t==i-1))
00045 G.new_edge(N[s],N[t], 0);
00046 }
00047 cout<<j<<" ";
00048 };
00049 is>>j;
00050 cout<<endl;
00051 };
00052
00053
00054
00055 ILP_Problem IP(Optsense_Min);
00056
00057 edge e;
00058 row_map<edge> VM, VM1;
00059 forall_edges(e, G) {
00060 VM[e]=IP.add_variable(G[e],0,1, Vartype_Integer);
00061 if((source(e)!=N[i-1]) && (target(e)!=N[i-1]))
00062 VM1[e]=VM[e];
00063 };
00064
00065 IP.add_sym_constraint(new ATOUR(G, VM));
00066
00067 prec p;
00068 forall(p, PL) {
00069 IP.add_sym_constraint(new PATH(G, p.first(), p.second(), VM1));
00070 };
00071
00072
00073
00074 IP.optimize();
00075
00076 forall_edges(e, G) if(IP.get_solution(VM[e])==1) {
00077 cout<<G[source(e)]<<" "<<G[target(e)]<<" edge\n";
00078 };
00079
00080
00081 };
00082