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

Diameter_Constraint_Minimum_Spanning_Tree

#define K 4

void ComputeDMST(graph& G, edge_array<double>& Cost, list<edge>& T) {

  ILP_Problem IP(Optsense_Min);

  graph H;

  node_array<node> GtoH[K];
  for(int i=0; i<K; i++) GtoH[i].init(G);

  edge e,f;
  var_map<edge> VM;
  edge_map<edge> EM(H);
  node u;
  forall_nodes(u, G) {
    for(int i=0; i<K; i++) { 
      GtoH[i][u]=H.new_node();
      if(i!=0) {
        f=H.new_edge(GtoH[i-1][u],GtoH[i][u]);
        VM[f]=IP.add_variable(0,0,1,Vartype_Integer);
        EM[f]=nil;
      };
    };
  };

  cout<<"NODES\n";

  forall_edges(e, G) {
    for(int i=1; i<K; i++) {
      f=H.new_edge(GtoH[i-1][source(e)],GtoH[i][target(e)]);
      VM[f]=IP.add_variable(Cost[e],0,1,Vartype_Integer);
      EM[f]=e;
    }
  }

  cout<<"EDGES\n";
 
  node s=GtoH[0][G.first_node()];
  forall_nodes(u,G) {
    IP.add_sym_constraint(new PATH(H, s, GtoH[K-1][u], VM));
  }

  cout<<"CONSTR\n";

  IP.optimize();

  cout<<"OPT\n";

  forall_edges(e, H) if((EM[e]!=nil) && (IP.get_solution(VM[e])==1))
    T.append(EM[e]);
};


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