src/demo/lp_demo.cc
changeset 1325 916ec8699dc3
parent 1309 b3ce42a4d7d2
child 1326 85f1c483279e
equal deleted inserted replaced
0:eef3701a700f 1:990ac90810a2
    35     LpGlpk::Expr ex;
    35     LpGlpk::Expr ex;
    36     for(InEdgeIt  e(g,t);e!=INVALID;++e) ex+=x[e];
    36     for(InEdgeIt  e(g,t);e!=INVALID;++e) ex+=x[e];
    37     for(OutEdgeIt e(g,t);e!=INVALID;++e) ex-=x[e];
    37     for(OutEdgeIt e(g,t);e!=INVALID;++e) ex-=x[e];
    38     lp.setObj(ex);
    38     lp.setObj(ex);
    39   }
    39   }
    40 
    40   lp.max();
    41   lp.solve();
    41   lp.solve();
    42 
    42 
    43   return 0;
    43   return lp.primalValue();
    44 }
    44 }
    45 
    45 
    46 int main() 
    46 int main() 
    47 {
    47 {
    48   LpGlpk lp_glpk;
    48   LpGlpk lp_glpk;
    49 
    49 
    50   ListGraph g;
    50   ListGraph g;
    51   ListGraph::Node s=g.addNode();
    51   ListGraph::Node s;
    52   ListGraph::Node t=g.addNode();
    52   ListGraph::Node t;
       
    53   
    53 
    54 
    54   ListGraph::EdgeMap<double> cap(g);
    55   ListGraph::EdgeMap<double> cap(g);
    55   
    56   
    56   GraphReader<ListGraph> reader(std::cin,g);
    57   GraphReader<ListGraph> reader(std::cin,g);
    57   reader.addEdgeMap("capacity",cap).run();
    58   reader.addNode("source",s).addNode("target",t)
       
    59     .addEdgeMap("capacity",cap).run();
    58   
    60   
    59   maxFlow(g,cap,s,t);
    61   // std::ifstream file("../test/preflow_");
       
    62 //   readDimacs(file, g, cap, s, t);
       
    63 
       
    64   std::cout << "Max flow value = " << maxFlow(g,cap,s,t) << std::endl;
    60 
    65 
    61 }
    66 }