Skip to content

Commit

Permalink
Complete (unstable) functor for #9 + Remove useless comments
Browse files Browse the repository at this point in the history
  • Loading branch information
arnaud-m committed Feb 21, 2012
1 parent e7d903e commit 34b2450
Show file tree
Hide file tree
Showing 10 changed files with 57 additions and 108 deletions.
11 changes: 1 addition & 10 deletions src/abstract_solver.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,9 @@ class abstract_solver {
// called before objective definitions
virtual int begin_objectives(void) { return 0; };

// get the current coefficient value of the objective function for parameter package
//FIXME virtual CUDFcoefficient get_obj_coeff(CUDFVersionedPackage *package) { return 0; };
// get the current coefficient value of the objective function for variable rank
virtual CUDFcoefficient get_obj_coeff(int rank) { return 0; };

// set objective coefficient value according to a package
//FIXME virtual int set_obj_coeff(CUDFVersionedPackage *package, CUDFcoefficient value) { return 0; };
// set objective coefficient value according to a rank (column number)
virtual int set_obj_coeff(int rank, CUDFcoefficient value) { return 0; };

Expand All @@ -61,13 +57,9 @@ class abstract_solver {
// called before the definition of a new constraint
virtual int new_constraint(void) { return 0; };

// get current constraint coefficient according to a package
//FIXME virtual CUDFcoefficient get_constraint_coeff(CUDFVersionedPackage *package) { return 0; };
// get current constraint coefficient according to a rank
virtual CUDFcoefficient get_constraint_coeff(int rank) { return 0; };

// set constraint coefficient of a package
//FIXME virtual int set_constraint_coeff(CUDFVersionedPackage *package, CUDFcoefficient value) { return 0; };
// set constraint coefficient of a rank (i.e. column number)
virtual int set_constraint_coeff(int rank, CUDFcoefficient value) { return 0; };

Expand Down Expand Up @@ -97,8 +89,7 @@ class abstract_solver {
// get the objective value at the end of solving
virtual CUDFcoefficient objective_value() { return 0; };

// get the status of a package in the final configuration
//FIXME virtual CUDFcoefficient get_solution(CUDFVersionedPackage *package) { return 0; };
// get the status of a rank in the final configuration
virtual CUDFcoefficient get_solution(int k) { return 0; };

// ******************************************************************
Expand Down
69 changes: 44 additions & 25 deletions src/constraint_generation.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,23 +10,35 @@ bool generate_agregate_constraints = false;
int new_var = 0;
CUDFcoefficient min_bandwidth = 2; //TODO change value of min_bandwidth

struct GetVar {
struct SetPathCoeff {

public:
GetVar(RankMapper* rankM, abstract_solver* solver) : rankM(rankM), solver(solver) {

SetPathCoeff(RankMapper* rankM, abstract_solver* solver) : rankM(rankM), solver(solver), stage(0) {

}
~GetVar() {

~SetPathCoeff() {
rankM = NULL;
solver = NULL;
}
inline unsigned int getStage() const { return stage; }
inline void setStage(unsigned int stage) { this->stage = stage; };

inline unsigned int getVarType() const { return varBorZ; }
inline void setVarType(bool varBorZ) { this->varBorZ = varBorZ; };
void operator()(FacilityNode* s, FacilityNode* d) {
int rank = rankM->rankB(s, d, 0);
solver->set_constraint_coeff(rank, 1);;
int rank = varBorZ ? rankM->rankB(s, d, stage) : rankM->rankZ(s, d, stage);
solver->set_constraint_coeff(rank, 1);
;
}
private :
RankMapper* rankM;
abstract_solver* solver;

private:
RankMapper *rankM;
abstract_solver *solver;
unsigned int stage;
bool varBorZ;

};

// Generate MILP objective function(s) and constraints for a given solver
Expand Down Expand Up @@ -80,6 +92,14 @@ int generate_constraints(PSLProblem *problem, abstract_solver &solver, abstract_
///////////
//connections flow conservation
//TODO 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 ?
//standard case: groups of clients
for (int s = 1; s < problem->getNbGroups() + 1; ++s) {
solver.new_constraint();
Expand All @@ -89,35 +109,34 @@ int generate_constraints(PSLProblem *problem, abstract_solver &solver, abstract_
for(LinkListIterator l = i->cbegin(); l != i->cend() ; l++) {
solver.set_constraint_coeff( rankM->rankY(*l, s), -1);
}
solver.add_constraint_eq(i->getType()->getDemand(s - 1)); //TODO check demand index
solver.add_constraint_eq(i->getType()->getDemand(s - 1));
}

}

GetVar getV(rankM, &solver);
SetPathCoeff setPC(rankM, &solver);
///////////////////////
//for each link ...
///////////////////////
for(LinkIterator l = problem->getRoot()->lbegin() ; l!= problem->getRoot()->lend() ; l++) {
///////////
//for each stage ...
for (int s = 0; s < problem->getNbGroups() + 1; ++s) {
///////////
//number of connections passing through the link
solver.new_constraint();
solver.set_constraint_coeff(rankM->rankY(*l, s), 1);
//FIXME l->forEachPath(getV);
//solver.set_constraint_coeff(rankM->rankZ(source, dest, s), -1);
solver.add_constraint_eq(0);

///////////
//for each stage ...
for (int s = 0; s < problem->getNbGroups() + 1; ++s) {
setPC.setStage(s);
for(LinkIterator l = problem->getRoot()->lbegin() ; l!= problem->getRoot()->lend() ; l++) {
///////////
//bandwidth passing through the link
setPC.setVarType(true);
solver.new_constraint();
// TODO l->forEachPath();
//solver.set_constraint_coeff(rankM->rankB(source, dest, s), -1);
solver.add_constraint_leq(l->getBandwidth());


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

Expand All @@ -131,7 +150,7 @@ int generate_constraints(PSLProblem *problem, abstract_solver &solver, abstract_
//for each stage ...
for (int s = 0; s < problem->getNbGroups() + 1; ++s) {
///////////
//minimal bandwidth for a connection
//minimal bandwidth for a single connection
solver.new_constraint();
solver.set_constraint_coeff(rankM->rankB(*i, *j, s), 1);
solver.set_constraint_coeff(rankM->rankZ(*i, *j, s), - min_bandwidth);
Expand Down
1 change: 1 addition & 0 deletions src/constraint_generation.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,5 +42,6 @@ extern CUDFcoefficient min_bandwidth;
// main function for constraint generation (translate a CUDF problem into MILP problem for a given solver and a given criteria)
extern int generate_constraints(PSLProblem *problem, abstract_solver &solver, abstract_combiner &combiner);


#endif

7 changes: 1 addition & 6 deletions src/cplex_solver.c
Original file line number Diff line number Diff line change
Expand Up @@ -276,8 +276,7 @@ int cplex_solver::init_solutions() {
return 0;
}

// get the computed status of a package (0 = uninstalled, 1 = installed)
//CUDFcoefficient cplex_solver::get_solution(CUDFVersionedPackage *package) { return (CUDFcoefficient)nearbyint(solution[package->rank]); }

CUDFcoefficient cplex_solver::get_solution(int k) { return (CUDFcoefficient)nearbyint(solution[k]); }

// initialize the objective function
Expand All @@ -288,14 +287,10 @@ int cplex_solver::begin_objectives(void) {
return 0;
}

// return the objective function coefficient of a package
//CUDFcoefficient cplex_solver::get_obj_coeff(CUDFVersionedPackage *package) { return (CUDFcoefficient)get_coeff(package); }

// return the objective function coefficient of a rank
CUDFcoefficient cplex_solver::get_obj_coeff(int rank) { return (CUDFcoefficient)get_coeff(rank); }

// set the objective function coefficient of a package
//int cplex_solver::set_obj_coeff(CUDFVersionedPackage *package, CUDFcoefficient value) { set_coeff(package, value); return 0; }

// set the objective function coefficient of a ranked variable
int cplex_solver::set_obj_coeff(int rank, CUDFcoefficient value) { set_coeff(rank, value); return 0; };
Expand Down
9 changes: 0 additions & 9 deletions src/cplex_solver.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,8 @@ class cplex_solver: public abstract_solver, public scoeff_solver<double, 0, 0> {

// Init the objective function definitions
int begin_objectives(void);
// Get current objective coefficient of package
//FIXME CUDFcoefficient get_obj_coeff(CUDFVersionedPackage *package);
// Get current objective coefficient of a column
CUDFcoefficient get_obj_coeff(int rank);
// Set current objective coefficient of package
//FIXME int set_obj_coeff(CUDFVersionedPackage *package, CUDFcoefficient value);
// Set current objective coefficient of column
int set_obj_coeff(int rank, CUDFcoefficient value);
// Begin the definition of a new objective
Expand All @@ -46,12 +42,8 @@ class cplex_solver: public abstract_solver, public scoeff_solver<double, 0, 0> {
int begin_add_constraints(void);
// Begin the definition of a new constraint
int new_constraint(void);
// Get current constraint coefficient of a package
//FIXME CUDFcoefficient get_constraint_coeff(CUDFVersionedPackage *package);
// Get current constraint coefficient of a column
CUDFcoefficient get_constraint_coeff(int rank);
// Set current constraint coefficient of a package
//FIXME int set_constraint_coeff(CUDFVersionedPackage *package, CUDFcoefficient value);
// Set current constraint coefficient of a column
int set_constraint_coeff(int rank, CUDFcoefficient value);
// Add current constraint as a more or equal constraint
Expand All @@ -73,7 +65,6 @@ class cplex_solver: public abstract_solver, public scoeff_solver<double, 0, 0> {
// Init solutions (required before calling get_solution)
int init_solutions();
// Get the solution for a package
//FIXME CUDFcoefficient get_solution(CUDFVersionedPackage *package);
// Get the solution for a column
CUDFcoefficient get_solution(int k);

Expand Down
24 changes: 8 additions & 16 deletions src/cudf.c
Original file line number Diff line number Diff line change
Expand Up @@ -435,25 +435,25 @@ CriteriaList *process_criteria(char *crit_descr, unsigned int &pos, bool first_l

// handle criteria
if (strncmp(crit_descr+crit_name, "removed", crit_name_length) == 0) {
; //FIXME criteria->push_back(new removed_criteria(get_criteria_lambda(crit_descr, pos, crit_descr[sign])));
; // criteria->push_back(new removed_criteria(get_criteria_lambda(crit_descr, pos, crit_descr[sign])));
} else if (strncmp(crit_descr+crit_name, "changed", crit_name_length) == 0) {
; //FIXME criteria->push_back(new changed_criteria(get_criteria_lambda(crit_descr, pos, crit_descr[sign])));
; // criteria->push_back(new changed_criteria(get_criteria_lambda(crit_descr, pos, crit_descr[sign])));
} else if (strncmp(crit_descr+crit_name, "new", crit_name_length) == 0) {
criteria->push_back(new new_criteria(get_criteria_lambda(crit_descr, pos, crit_descr[sign])));
; //FIXME criteria->push_back(new notuptodate_criteria(get_criteria_lambda(crit_descr, pos, crit_descr[sign])));
; // criteria->push_back(new notuptodate_criteria(get_criteria_lambda(crit_descr, pos, crit_descr[sign])));
} else if (strncmp(crit_descr+crit_name, "nunsat", crit_name_length) == 0) {
bool with_providers = true;
char *property_name = get_criteria_property_name_and_bool(crit_descr, pos, with_providers);
if (property_name != (char *)NULL) {
; //FIXME abstract_criteria *crit = new nunsat_criteria(property_name, with_providers, get_criteria_lambda(crit_descr, pos, crit_descr[sign]));
; //abstract_criteria *crit = new nunsat_criteria(property_name, with_providers, get_criteria_lambda(crit_descr, pos, crit_descr[sign]));
//criteria_with_property->push_back(crit);
//criteria->push_back(crit);
}
} else if (strncmp(crit_descr+crit_name, "count", crit_name_length) == 0) {
bool onlynew = false;
char *property_name = get_criteria_property_name_and_bool(crit_descr, pos, onlynew);
if (property_name != (char *)NULL) {
; //FIXME abstract_criteria *crit = new count_criteria(property_name, onlynew, get_criteria_lambda(crit_descr, pos, crit_descr[sign]));
; //abstract_criteria *crit = new count_criteria(property_name, onlynew, get_criteria_lambda(crit_descr, pos, crit_descr[sign]));
//criteria_with_property->push_back(crit);
//criteria->push_back(crit);
}
Expand Down Expand Up @@ -517,7 +517,7 @@ int main(int argc, char *argv[]) {
bool fulloutput = false;
PSLProblem *problem;
vector<abstract_criteria *> criteria_with_property;

//TODO remove useless options;
// parameter handling
if (argc > 1) {
for (int i = 1; i < argc; i++) {
Expand Down Expand Up @@ -548,6 +548,7 @@ int main(int argc, char *argv[]) {
exit(-1);
}
}

} else if (strcmp(argv[i], "-fo") == 0) {
fulloutput = true;
} else if (strncmp(argv[i], "-v", 2) == 0) {
Expand All @@ -564,7 +565,7 @@ int main(int argc, char *argv[]) {
} else if (strcmp(argv[i], "-cov") == 0) {
criteria_opt_var = true;
} else if (strcmp(argv[i], "-noreduce") == 0) {
; //FIXME use_reduced = false;
;
} else if (strncmp(argv[i], "-lex[", 5) == 0) {
CriteriaList *criteria = get_criteria(argv[i]+4, true, &criteria_with_property);
if (criteria->size() > 0)
Expand Down Expand Up @@ -737,15 +738,6 @@ int main(int argc, char *argv[]) {
combiner = new lexicographic_combiner(criteria);
}

// reduce the problem (if use_reduced is true)
// if (combiner->can_reduce()) {
// if (verbosity > 0) fprintf(stdout, "Can reduce graph.\n");
// } else {
// // FIXME use_reduced = false;
// if (verbosity > 0) fprintf(stdout, "Can NOT reduce graph.\n");
// }
//FIXME problem = compute_reduced_CUDF(the_problem);

problem = the_problem;
// combiner initialization
combiner->initialize(problem, solver);
Expand Down
5 changes: 0 additions & 5 deletions src/glpk_solver.c
Original file line number Diff line number Diff line change
Expand Up @@ -112,14 +112,9 @@ int glpk_solver::begin_objectives(void) {
return 0;
}

// return the package coefficient of the objective function
//CUDFcoefficient glpk_solver::get_obj_coeff(CUDFVersionedPackage *package) { return (CUDFcoefficient)get_coeff(package); }

// return the package coefficient of the objective function
CUDFcoefficient glpk_solver::get_obj_coeff(int rank) { return (CUDFcoefficient)get_coeff(rank); }

// set package coefficient to a value
//int glpk_solver::set_obj_coeff(CUDFVersionedPackage *package, CUDFcoefficient value) { set_coeff(package, value); return 0; }
// set column coefficient to a value
int glpk_solver::set_obj_coeff(int rank, CUDFcoefficient value) { set_coeff(rank, value); return 0; }

Expand Down
11 changes: 1 addition & 10 deletions src/glpk_solver.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,17 +35,12 @@ class glpk_solver: public abstract_solver, public scoeff_solver<double, 1, 1> {
CUDFcoefficient objective_value();
// Init solutions (required before calling get_solution)
int init_solutions();
// Get the solution for a package
//CUDFcoefficient get_solution(CUDFVersionedPackage *package);


// Init the objective function definitions
int begin_objectives(void);
// Get current objective coefficient of package
//CUDFcoefficient get_obj_coeff(CUDFVersionedPackage *package);
// Get current objective coefficient of a column
CUDFcoefficient get_obj_coeff(int rank);
// Set current objective coefficient of package
//int set_obj_coeff(CUDFVersionedPackage *package, CUDFcoefficient value);
// Set current objective coefficient of column
int set_obj_coeff(int rank, CUDFcoefficient value);
// Begin the definition of a new objective
Expand All @@ -59,12 +54,8 @@ class glpk_solver: public abstract_solver, public scoeff_solver<double, 1, 1> {
int begin_add_constraints(void);
// Begin the definition of a new constraint
int new_constraint(void);
// Get current constraint coefficient of a package
//CUDFcoefficient get_constraint_coeff(CUDFVersionedPackage *package);
// Get current constraint coefficient of a column
CUDFcoefficient get_constraint_coeff(int rank);
// Set current constraint coefficient of a package
//int set_constraint_coeff(CUDFVersionedPackage *package, CUDFcoefficient value);
// Set current constraint coefficient of a column
int set_constraint_coeff(int rank, CUDFcoefficient value);
// Add current constraint as a more or equal constraint
Expand Down
17 changes: 0 additions & 17 deletions src/lp_solver.c
Original file line number Diff line number Diff line change
Expand Up @@ -241,23 +241,14 @@ int lp_solver::set_intvar_range(int rank, CUDFcoefficient lower, CUDFcoefficient
return 0;
}

// return the status of a package within the final configuration
//CUDFcoefficient lp_solver::get_solution(CUDFVersionedPackage *package) { return solution[package->rank]; }

// initialize objective function
int lp_solver::begin_objectives(void) { return 0; }

// return the package coefficient of the objective function
//CUDFcoefficient lp_solver::get_obj_coeff(CUDFVersionedPackage *package) { return get_coeff(package); }

// return the package coefficient of the objective function
CUDFcoefficient lp_solver::get_obj_coeff(int rank) { return get_coeff(rank); }

// set the package coefficient of the objective function
//int lp_solver::set_obj_coeff(CUDFVersionedPackage *package, CUDFcoefficient value) {
// set_coeff(package, value);
// return 0;
//}

// set the column coefficient of the objective function
int lp_solver::set_obj_coeff(int rank, CUDFcoefficient value) {
Expand Down Expand Up @@ -288,18 +279,10 @@ int lp_solver::new_constraint(void) {
return 0;
}

// get the package coefficient of the current constraint
//CUDFcoefficient lp_solver::get_constraint_coeff(CUDFVersionedPackage *package) { return get_coeff(package); }

// get the package coefficient of the current constraint
CUDFcoefficient lp_solver::get_constraint_coeff(int rank) { return get_coeff(rank); }

// set package coefficient of the current constraint
//int lp_solver::set_constraint_coeff(CUDFVersionedPackage *package, CUDFcoefficient value) {
// set_coeff(package, value);
// return 0;
//}

// set column coefficient of the current constraint
int lp_solver::set_constraint_coeff(int rank, CUDFcoefficient value) {
set_coeff(rank, value);
Expand Down
Loading

0 comments on commit 34b2450

Please sign in to comment.