Skip to content

Commit

Permalink
feasible model (#9) for the minimization of the number of servers (#10)
Browse files Browse the repository at this point in the history
  • Loading branch information
arnaud-m committed Feb 26, 2012
1 parent 9529ed7 commit 5b165ab
Show file tree
Hide file tree
Showing 6 changed files with 100 additions and 112 deletions.
99 changes: 58 additions & 41 deletions src/constraint_generation.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ bool generate_desagregate_constraints = true;
bool generate_agregate_constraints = false;

int new_var = 0;
CUDFcoefficient min_bandwidth = 2; //TODO change value of min_bandwidth
CUDFcoefficient min_bandwidth = 0; //TODO set min_bandwidth to 1Ko

struct SetPathCoeff {

Expand Down Expand Up @@ -86,7 +86,6 @@ int generate_constraints(PSLProblem *problem, abstract_solver &solver, abstract_
}
///////////
//limit the number of connections provided by facilities for a given stage
//FIXME I believe that stage are false
for (int s = 0; s < problem->stageCount(); ++s) {
solver.new_constraint();
solver.set_constraint_coeff( problem->rankY(*i, s), -1);
Expand All @@ -95,29 +94,47 @@ int generate_constraints(PSLProblem *problem, abstract_solver &solver, abstract_
}
solver.add_constraint_geq(0);
}

///////////
//Additional constraints for the initial broadcast(s=0)
if(i->isRoot()) {
//the central facility contains the root pserver
solver.new_constraint();
solver.set_constraint_coeff( problem->rankX(*i, 0), 1);
solver.add_constraint_geq(1);
} else {
//other facilities only receive the initial broadcast
solver.new_constraint();
solver.set_constraint_coeff( problem->rankY(*i, 0), 1);
solver.add_constraint_eq(0);
}


///////////
//connections flow conservation
//special case: initial broadcast (s=0)
// solver.new_constraint();
// if(! i->isRoot()) {
// solver.set_constraint_coeff( problem->rankY(i->toFather(), 0), 1);
// }
// for(LinkListIterator l = i->cbegin(); l != i->cend() ; l++) {
// solver.set_constraint_coeff( problem->rankY(*l, 0), -1);
// }
// solver.set_constraint_coeff( problem->rankX(*i), -1); //the pserver demand
// solver.add_constraint_eq(0);
// //standard case: groups of clients
// for (int s = 1; s < problem->groupCount() + 1; ++s) {
// solver.new_constraint();
// if(! i->isRoot()) {
// solver.set_constraint_coeff( problem->rankY(i->toFather(), s), 1);
// }
// for(LinkListIterator l = i->cbegin(); l != i->cend() ; l++) {
// solver.set_constraint_coeff( problem->rankY(*l, s), -1);
// }
// solver.add_constraint_eq(i->getType()->getDemand(s - 1));
// }
solver.new_constraint();
if(! i->isRoot()) {
solver.set_constraint_coeff( problem->rankY(i->toFather(), 0), 1);
}
solver.set_constraint_coeff( problem->rankY(*i, 0), 1);
for(LinkListIterator l = i->cbegin(); l != i->cend() ; l++) {
solver.set_constraint_coeff( problem->rankY(*l, 0), -1);
}
solver.set_constraint_coeff( problem->rankX(*i), -1); //the pserver demand
solver.add_constraint_eq(0);
//standard case: groups of clients
for (int s = 1; s < problem->stageCount(); ++s) {
solver.new_constraint();
if(! i->isRoot()) {
solver.set_constraint_coeff( problem->rankY(i->toFather(), s), 1);
}
solver.set_constraint_coeff( problem->rankY(*i, s), 1);
for(LinkListIterator l = i->cbegin(); l != i->cend() ; l++) {
solver.set_constraint_coeff( problem->rankY(*l, s), -1);
}
solver.add_constraint_eq(i->getType()->getDemand(s - 1));
}

}

Expand All @@ -127,25 +144,25 @@ int generate_constraints(PSLProblem *problem, abstract_solver &solver, abstract_
///////////////////////
///////////
//for each stage ...
// for (int s = 0; s < problem->groupCount() + 1; ++s) {
// setPC.setStage(s);
// for(LinkIterator l = problem->lbegin() ; l!= problem->lend() ; l++) {
// ///////////
// //bandwidth passing through the link
// setPC.setVarType(true);
// solver.new_constraint();
// l->forEachPath(setPC);
// solver.add_constraint_leq(l->getBandwidth());
//
// ///////////
// //number of connections passing through the link
// setPC.setVarType(false);
// solver.new_constraint();
// solver.set_constraint_coeff(problem->rankY(*l, s), -1);
// l->forEachPath(setPC);
// solver.add_constraint_eq(0);
// }
// }
for (int s = 0; s < problem->groupCount() + 1; ++s) {
setPC.setStage(s);
for(LinkIterator l = problem->lbegin() ; l!= problem->lend() ; l++) {
///////////
//bandwidth passing through the link
setPC.setVarType(true);
solver.new_constraint();
l->forEachPath(setPC);
solver.add_constraint_leq(l->getBandwidth());

///////////
//number of connections passing through the link
setPC.setVarType(false);
solver.new_constraint();
solver.set_constraint_coeff(problem->rankY(*l, s), -1);
l->forEachPath(setPC);
solver.add_constraint_eq(0);
}
}

///////////////////////
//for each path ...
Expand Down
21 changes: 19 additions & 2 deletions src/cudf.c
Original file line number Diff line number Diff line change
Expand Up @@ -822,14 +822,31 @@ int parse_pslp(istream& in)
//TODO add option for hierarchical network
bool hierarchical=true;
the_problem->generateNetwork(hierarchical);
return 0;
}

ofstream myfile;
myfile.open ("graphpbs.dot");
//myfile.open ("/tmp/pserver.dot");
the_problem->toDotty(myfile);

return 0;
}

void print_problem(ostream& out, PSLProblem *pbs)
{
cout << *pbs;
}


void print_solution(ostream& out, PSLProblem *problem, abstract_solver solver) {
// for(NodeIterator i = problem->nbegin() ; i!= problem->nend() ; i++) {
//
// }
}

void flow2dotty(PSLProblem *problem, abstract_solver solver, unsigned int stage) {

}

void path2dotty(PSLProblem *problem, abstract_solver solver, unsigned int stage) {

}
5 changes: 1 addition & 4 deletions src/cudf.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,7 @@ extern int verbosity;

// Print out a CUDF problem
// requires the file descriptor of the targeted file and a pointer to the PSL problem
extern void print_problem(ostream& in, PSLProblem *pbs);

//cudf.y
//------------------------------------------------------------------
extern void print_problem(ostream& out, PSLProblem *pbs);



Expand Down
2 changes: 2 additions & 0 deletions src/network.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -547,6 +547,8 @@ class PSLProblem {
//
void deleteTree(FacilityNode* node) {
levelNodeCounts.clear();
levelCumulNodeCounts.clear();
lengthCumulPathCounts.clear();
_nodeCount = 0;
if(node != NULL) {
for ( size_t i = 0; i < node->getChildrenCount(); ++i ) {
Expand Down
79 changes: 18 additions & 61 deletions src/new_criteria.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,95 +10,52 @@

// Criteria initialization
void new_criteria::initialize(PSLProblem *problem, abstract_solver *solver) {
this->problem = problem;
this->solver = solver;
range = 0;
// for (CUDFVirtualPackageListIterator ivpkg = problem->all_virtual_packages->begin(); ivpkg != problem->all_virtual_packages->end(); ivpkg++) {
// int size = (*ivpkg)->all_versions.size();
// if ((size > 0) && ((*ivpkg)->highest_installed == (CUDFVersionedPackage *)NULL)) {
// all_uninstalled_versioned_virtual_packages.push_back((*ivpkg));
// if (size > 1) range++;
// }
// }
this->problem = problem;
this->solver = solver;
_upper_bound = 0;
for(NodeIterator i = problem->nbegin() ; i!= problem->nend() ; i++) {
_upper_bound += i->getType()->getTotalCapacity();
}
}

// Computing the number of columns required to handle the criteria
int new_criteria::set_variable_range(int first_free_var) {
this->first_free_var = first_free_var;
return first_free_var + range;
return first_free_var;
}

// Add the criteria to the current objective function
int new_criteria::add_criteria_to_objective(CUDFcoefficient lambda) {
// int ivpkg_rank = first_free_var;
// for (CUDFVirtualPackageListIterator ivpkg = all_uninstalled_versioned_virtual_packages.begin();
// ivpkg != all_uninstalled_versioned_virtual_packages.end(); ivpkg++)
// if ((*ivpkg)->all_versions.size() == 1) {
// CUDFVersionedPackage *pkg = *((*ivpkg)->all_versions.begin());
// solver->set_obj_coeff(pkg, lambda_crit * lambda + solver->get_obj_coeff(pkg));
// } else
// solver->set_obj_coeff(ivpkg_rank++, lambda_crit * lambda);
return 0;
for(NodeIterator i = problem->nbegin() ; i!= problem->nend() ; i++) {
solver->set_obj_coeff(problem->rankX(*i), lambda_crit * lambda + solver->get_obj_coeff(problem->rankX(*i)));
}
return 0;
}

// Add the criteria to the constraint set
int new_criteria::add_criteria_to_constraint(CUDFcoefficient lambda) {
// int ivpkg_rank = first_free_var;
// for (CUDFVirtualPackageListIterator ivpkg = all_uninstalled_versioned_virtual_packages.begin();
// ivpkg != all_uninstalled_versioned_virtual_packages.end(); ivpkg++)
// if ((*ivpkg)->all_versions.size() == 1)
// solver->set_constraint_coeff(*((*ivpkg)->all_versions.begin()), lambda_crit * lambda);
// else
// solver->set_constraint_coeff(ivpkg_rank++, lambda_crit * lambda);
return 0;
for(NodeIterator i = problem->nbegin() ; i!= problem->nend() ; i++) {
solver->set_constraint_coeff(problem->rankX(*i), lambda_crit * lambda);
}
return 0;
}

// Add the constraints required by the criteria
int new_criteria::add_constraints() {
// int ivpkg_rank = first_free_var;
// for (CUDFVirtualPackageListIterator ivpkg = all_uninstalled_versioned_virtual_packages.begin();
// ivpkg != all_uninstalled_versioned_virtual_packages.end(); ivpkg++) {
// solver->new_constraint();
// if ((*ivpkg)->all_versions.size() > 1) {
// for (CUDFVersionedPackageSetIterator vers_pkg = (*ivpkg)->all_versions.begin(); vers_pkg != (*ivpkg)->all_versions.end(); vers_pkg++)
// solver->set_constraint_coeff((*vers_pkg)->rank, +1);
// solver->set_constraint_coeff(ivpkg_rank, -1);
// solver->add_constraint_geq(0);
// solver->new_constraint();
// for (CUDFVersionedPackageSetIterator vers_pkg = (*ivpkg)->all_versions.begin(); vers_pkg != (*ivpkg)->all_versions.end(); vers_pkg++)
// solver->set_constraint_coeff((*vers_pkg)->rank, +1);
// {
// int n = (*ivpkg)->all_versions.size();
// solver->set_constraint_coeff(ivpkg_rank, -n);
// solver->add_constraint_leq(0);
// }
// ivpkg_rank++;
// }
// }
return 0;
return 0;
}

// Compute the criteria range
CUDFcoefficient new_criteria::bound_range() {
return 0;
//return CUDFabs(lambda_crit) * all_uninstalled_versioned_virtual_packages.size();
return CUDFabs(lambda_crit) * _upper_bound;
}

// Compute the criteria upper bound
CUDFcoefficient new_criteria::upper_bound() {
return 0;
// if (lambda_crit >= 0)
// return lambda_crit * all_uninstalled_versioned_virtual_packages.size();
// else
// return 0;
return _upper_bound;
}

// Compute the criteria lower bound
CUDFcoefficient new_criteria::lower_bound() {
// if (lambda_crit >= 0)
// return 0;
// else
// return lambda_crit * all_uninstalled_versioned_virtual_packages.size();
return 0;
}

Expand Down
6 changes: 2 additions & 4 deletions src/new_criteria.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,8 @@ class new_criteria: public abstract_criteria {
// list of all uninstalled virtual packaged with at list a versionned package
//CUDFVirtualPackageList all_uninstalled_versioned_virtual_packages;

// range of the criteria
int range;
// column of the first variable used by the criteria
int first_free_var;
// upper bound of the criteria
int _upper_bound;

// Allocate some columns for the criteria
int set_variable_range(int first_free_var);
Expand Down

0 comments on commit 5b165ab

Please sign in to comment.