Skip to content

Commit

Permalink
Add basic diagnostics (#25)
Browse files Browse the repository at this point in the history
  • Loading branch information
arnaud-m committed Jul 2, 2012
1 parent 4bddc08 commit ddbee3d
Show file tree
Hide file tree
Showing 6 changed files with 72 additions and 12 deletions.
13 changes: 13 additions & 0 deletions src/abstract_solver.h
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,19 @@ class abstract_solver {
// get the status of a rank in the final configuration
virtual CUDFcoefficient get_solution(int k) { return 0; };

// get the number of solutions found at the end of solving
virtual int solutionCount() { return 0; };

// get the number of objectives (or sub-problems).
virtual int objectiveCount() { return 0; };

// get the number of nodes at the end of solving
virtual int nodeCount() { return 0; };

// get the solving time.
virtual int timeCount() { return 0; };


// ******************************************************************
// abstract solver destructor
virtual ~abstract_solver() {};
Expand Down
20 changes: 16 additions & 4 deletions src/cplex_solver.c
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
#include <cplex_solver.h>
#include <math.h>

//TODO Replace by verbosity
#define USEXNAME 0

// solver creation
Expand All @@ -19,7 +18,9 @@ abstract_solver *new_cplex_solver() { return new cplex_solver(); }
// requires the list of versioned packages and the total amount of variables (including additional ones)
int cplex_solver::init_solver(PSLProblem *problem, int other_vars) {
int status;

solution_count = 0;
node_count = 0;
time_count = 0;

// Coefficient initialization
initialize_coeffs(problem->rankCount() + other_vars);
Expand Down Expand Up @@ -181,10 +182,15 @@ int cplex_solver::solve() {
// Solve the objectives in a lexical order
for (int i = first_objective; i < nb_objectives; i++) {
// Solve the mip problem
//CPXsetintparam(env, CPX_PARAM_SOLNPOOLCAPACITY,1);
time_t stime = - time(NULL);
if (CPXmipopt (env, lp)) return 0;

stime += time(NULL);
// Get solution status
if ((mipstat = CPXgetstat(env, lp)) == CPXMIP_OPTIMAL) {
solution_count += CPXgetsolnpoolnumsolns(env, lp) + CPXgetsolnpoolnumreplaced(env, lp);
time_count += stime;
node_count += CPXgetnodecnt(env, lp);
if (i < nb_objectives - 1) {
// Get next non empty objective
// (must be done here to avoid conflicting method calls
Expand All @@ -206,7 +212,6 @@ int cplex_solver::solve() {

if (verbosity >= DEFAULT)
printf(">>>> Objective value %d = %f\n", previ, values[0]);

{
int status, begin[2];
double rhs[1];
Expand Down Expand Up @@ -424,3 +429,10 @@ int cplex_solver::end_add_constraints(void) {
if (verbosity >= VERBOSE) writelp(C_STR("cplexpb.lp"));
return 0;
}

int cplex_solver::objectiveCount()
{
return objectives.size();
}


16 changes: 15 additions & 1 deletion src/cplex_solver.h
Original file line number Diff line number Diff line change
Expand Up @@ -80,10 +80,18 @@ class cplex_solver: public abstract_solver, public scoeff_solver<double, 0, 0> {
CUDFcoefficient objective_value();
// Init solutions (required before calling get_solution)
int init_solutions();
// Get the solution for a package
// Get the solution for a column
CUDFcoefficient get_solution(int k);

// get the number of solutions found at the end of solving
int solutionCount(){return solution_count;}
// get the number of objectives (or sub-problems).
int objectiveCount();
// get the number of nodes at the end of solving
int nodeCount() {return node_count;}
// get the solving time.
int timeCount() {return time_count;}

// variables only for internal use (should be private)
CPXENVptr env; // cplex environment
CPXLPptr lp; // cplex linear program
Expand All @@ -104,6 +112,12 @@ class cplex_solver: public abstract_solver, public scoeff_solver<double, 0, 0> {
cplex_solver(void) {
solution = (double *)NULL;
}

private:
int solution_count;
int node_count;
double time_count;

};

#endif
32 changes: 27 additions & 5 deletions src/cudf.c
Original file line number Diff line number Diff line change
Expand Up @@ -675,7 +675,6 @@ void print_solution(ostream & out, PSLProblem *problem, abstract_solver *solver)
for (int k = 0; k < problem->serverTypeCount(); ++k) {
if(k > 0) out << ",";
out << solver->get_solution(problem->rankX(*i, k));

}
out << "}";
}
Expand All @@ -697,10 +696,33 @@ void export_solution(PSLProblem *problem, abstract_solver *solver,char* objectiv

void print_messages(ostream & out, PSLProblem *problem, abstract_solver *solver)
{
//Display spare clients.
out << "d TODO" << endl;
out << "c TODO" << endl;
}

out << "d TIME " << solver->timeCount() << endl;
out << "d NODES " << solver->nodeCount() << endl;
out << "d SOLUTIONS " << solver->solutionCount() << endl;
out << "d #OBJECTIVES " << solver->objectiveCount() << endl;
//Compute total pserver capacity
double capa = 0;
for(NodeIterator i = problem->nbegin() ; i!= problem->nend() ; i++) {
for (int k = 0; k < problem->serverTypeCount(); ++k) {
capa += solver->get_solution(problem->rankX(*i, k)) * problem->getServer(k)->getMaxConnections();
}
}
//Display spare capacity.
double avg_spare_capa;
for (int s = 1; s < problem->stageCount(); ++s) {
double clients = 0;
for(NodeIterator i = problem->nbegin() ; i!= problem->nend() ; i++) {
clients += solver->get_solution(problem->rankY(*i, s));
}
out.precision(2);
double spare_capa = (capa-clients)/capa;
avg_spare_capa += spare_capa;
out << "d SPARE_CAPA_S" << s << " " << fixed << spare_capa <<endl;
}
avg_spare_capa /= problem->groupCount();
out << "d SPARE_CAPA " << fixed << avg_spare_capa <<endl;
}



Expand Down
1 change: 0 additions & 1 deletion src/glpk_solver.h
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,6 @@ class glpk_solver: public abstract_solver, public scoeff_solver<double, 1, 1> {
int end_add_constraints(void);

glp_prob *lp; // internal solver representation
//CUDFVersionedPackageList *all_versioned_packages; // list of all versioned packages
int nb_packages; // number of packages

CUDFcoefficient *lb, *ub; // arrays of lower and upper bounds
Expand Down
2 changes: 1 addition & 1 deletion src/scoeff_solver.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
#include <vector>
#include <stdlib.h>
#include <stdio.h>
//#include <cudf.h>


// Template to allow coefficient saving
// mainly used to save objective coefficients
Expand Down

0 comments on commit ddbee3d

Please sign in to comment.