Skip to content

Commit

Permalink
Add initial broadcast flow constraints and total number of servers at a
Browse files Browse the repository at this point in the history
facility #9
  • Loading branch information
arnaud-m committed Feb 23, 2012
1 parent 102b29c commit 43bd3db
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 9 deletions.
22 changes: 15 additions & 7 deletions src/constraint_generation.c
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,9 @@ int generate_constraints(PSLProblem *problem, abstract_solver &solver, abstract_
//----------------------------------------------------------------------------------------------------
// Objective function
RankMapper* rankM = new RankMapper(*problem);
int nb_vars=rankM->size();//TODO nb_vars = nb_packages + new_var;
int nb_vars=rankM->size();
nb_vars = combiner.column_allocation(nb_vars);
int other_vars=nb_vars - rankM->size();//TODO other_vars=nb_vars - nb_packages
int other_vars=nb_vars - rankM->size();
solver.init_solver(problem, other_vars);
//TODO set_intvar_range(int rank, CUDFcoefficient lower, CUDFcoefficient upper);
solver.begin_objectives();
Expand All @@ -73,7 +73,16 @@ int generate_constraints(PSLProblem *problem, abstract_solver &solver, abstract_
///////////////////////
for(NodeIterator i = problem->getRoot()->nbegin() ; i!= problem->getRoot()->nend() ; i++) {
///////////
//limit the number of servers at facilities

//compute the total number of servers at facilities
solver.new_constraint();
solver.set_constraint_coeff( rankM->rankX(*i), -1);
for (int k = 0; k < problem->getNbServers(); ++k) {
solver.set_constraint_coeff( rankM->rankX(*i, k), 1);
}
solver.add_constraint_eq(0);

//limit the number of servers of a given type at facilities
for (int k = 0; k < problem->getNbServers(); ++k) {
solver.new_constraint();
solver.set_constraint_coeff( rankM->rankX(*i, k), 1);
Expand All @@ -91,15 +100,16 @@ int generate_constraints(PSLProblem *problem, abstract_solver &solver, abstract_
}
///////////
//connections flow conservation
//TODO special case: initial broadcast (s=0)
//special case: initial broadcast (s=0)
solver.new_constraint();
if(! i->isRoot()) {
solver.set_constraint_coeff( rankM->rankY(i->toFather(), 0), 1);
}
for(LinkListIterator l = i->cbegin(); l != i->cend() ; l++) {
solver.set_constraint_coeff( rankM->rankY(*l, 0), -1);
}
//solver.add_constraint_eq(i->getType()->getDemand(s - 1)); //TODO define Xi or set directly coeffs of Xik ?
solver.set_constraint_coeff( rankM->rankX(*i), -1); //the pserver demand
solver.add_constraint_eq(0);
//standard case: groups of clients
for (int s = 1; s < problem->getNbGroups() + 1; ++s) {
solver.new_constraint();
Expand Down Expand Up @@ -160,8 +170,6 @@ int generate_constraints(PSLProblem *problem, abstract_solver &solver, abstract_
}
}
solver.end_add_constraints();
//char* str = "/tmp/test.lp";
//solver.writelp(str);
return 0;
}

5 changes: 3 additions & 2 deletions src/network.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -434,7 +434,8 @@ class RankMapper {
public:
RankMapper(PSLProblem& problem);
~RankMapper() {}

//TODO remove Xi ?
//TODO Separate boolean, integer and real variables
int rankX(FacilityNode *node) const {
return node->getID();
}
Expand Down Expand Up @@ -537,7 +538,7 @@ class PSLProblem {
return facilities.size();
}

inline unsigned int getNetworkDepth() const {
inline unsigned int getNbLevels() const {
return levelNodeCounts.size();
}
//TODO inline bool isValid();
Expand Down

0 comments on commit 43bd3db

Please sign in to comment.