Skip to content

Commit ddbee3d

Browse files
committed
Add basic diagnostics (#25)
1 parent 4bddc08 commit ddbee3d

File tree

6 files changed

+72
-12
lines changed

6 files changed

+72
-12
lines changed

src/abstract_solver.h

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,19 @@ class abstract_solver {
107107
// get the status of a rank in the final configuration
108108
virtual CUDFcoefficient get_solution(int k) { return 0; };
109109

110+
// get the number of solutions found at the end of solving
111+
virtual int solutionCount() { return 0; };
112+
113+
// get the number of objectives (or sub-problems).
114+
virtual int objectiveCount() { return 0; };
115+
116+
// get the number of nodes at the end of solving
117+
virtual int nodeCount() { return 0; };
118+
119+
// get the solving time.
120+
virtual int timeCount() { return 0; };
121+
122+
110123
// ******************************************************************
111124
// abstract solver destructor
112125
virtual ~abstract_solver() {};

src/cplex_solver.c

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
#include <cplex_solver.h>
1010
#include <math.h>
1111

12-
//TODO Replace by verbosity
1312
#define USEXNAME 0
1413

1514
// solver creation
@@ -19,7 +18,9 @@ abstract_solver *new_cplex_solver() { return new cplex_solver(); }
1918
// requires the list of versioned packages and the total amount of variables (including additional ones)
2019
int cplex_solver::init_solver(PSLProblem *problem, int other_vars) {
2120
int status;
22-
21+
solution_count = 0;
22+
node_count = 0;
23+
time_count = 0;
2324

2425
// Coefficient initialization
2526
initialize_coeffs(problem->rankCount() + other_vars);
@@ -181,10 +182,15 @@ int cplex_solver::solve() {
181182
// Solve the objectives in a lexical order
182183
for (int i = first_objective; i < nb_objectives; i++) {
183184
// Solve the mip problem
185+
//CPXsetintparam(env, CPX_PARAM_SOLNPOOLCAPACITY,1);
186+
time_t stime = - time(NULL);
184187
if (CPXmipopt (env, lp)) return 0;
185-
188+
stime += time(NULL);
186189
// Get solution status
187190
if ((mipstat = CPXgetstat(env, lp)) == CPXMIP_OPTIMAL) {
191+
solution_count += CPXgetsolnpoolnumsolns(env, lp) + CPXgetsolnpoolnumreplaced(env, lp);
192+
time_count += stime;
193+
node_count += CPXgetnodecnt(env, lp);
188194
if (i < nb_objectives - 1) {
189195
// Get next non empty objective
190196
// (must be done here to avoid conflicting method calls
@@ -206,7 +212,6 @@ int cplex_solver::solve() {
206212

207213
if (verbosity >= DEFAULT)
208214
printf(">>>> Objective value %d = %f\n", previ, values[0]);
209-
210215
{
211216
int status, begin[2];
212217
double rhs[1];
@@ -424,3 +429,10 @@ int cplex_solver::end_add_constraints(void) {
424429
if (verbosity >= VERBOSE) writelp(C_STR("cplexpb.lp"));
425430
return 0;
426431
}
432+
433+
int cplex_solver::objectiveCount()
434+
{
435+
return objectives.size();
436+
}
437+
438+

src/cplex_solver.h

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,10 +80,18 @@ class cplex_solver: public abstract_solver, public scoeff_solver<double, 0, 0> {
8080
CUDFcoefficient objective_value();
8181
// Init solutions (required before calling get_solution)
8282
int init_solutions();
83-
// Get the solution for a package
8483
// Get the solution for a column
8584
CUDFcoefficient get_solution(int k);
8685

86+
// get the number of solutions found at the end of solving
87+
int solutionCount(){return solution_count;}
88+
// get the number of objectives (or sub-problems).
89+
int objectiveCount();
90+
// get the number of nodes at the end of solving
91+
int nodeCount() {return node_count;}
92+
// get the solving time.
93+
int timeCount() {return time_count;}
94+
8795
// variables only for internal use (should be private)
8896
CPXENVptr env; // cplex environment
8997
CPXLPptr lp; // cplex linear program
@@ -104,6 +112,12 @@ class cplex_solver: public abstract_solver, public scoeff_solver<double, 0, 0> {
104112
cplex_solver(void) {
105113
solution = (double *)NULL;
106114
}
115+
116+
private:
117+
int solution_count;
118+
int node_count;
119+
double time_count;
120+
107121
};
108122

109123
#endif

src/cudf.c

Lines changed: 27 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -675,7 +675,6 @@ void print_solution(ostream & out, PSLProblem *problem, abstract_solver *solver)
675675
for (int k = 0; k < problem->serverTypeCount(); ++k) {
676676
if(k > 0) out << ",";
677677
out << solver->get_solution(problem->rankX(*i, k));
678-
679678
}
680679
out << "}";
681680
}
@@ -697,10 +696,33 @@ void export_solution(PSLProblem *problem, abstract_solver *solver,char* objectiv
697696

698697
void print_messages(ostream & out, PSLProblem *problem, abstract_solver *solver)
699698
{
700-
//Display spare clients.
701-
out << "d TODO" << endl;
702-
out << "c TODO" << endl;
703-
}
699+
700+
out << "d TIME " << solver->timeCount() << endl;
701+
out << "d NODES " << solver->nodeCount() << endl;
702+
out << "d SOLUTIONS " << solver->solutionCount() << endl;
703+
out << "d #OBJECTIVES " << solver->objectiveCount() << endl;
704+
//Compute total pserver capacity
705+
double capa = 0;
706+
for(NodeIterator i = problem->nbegin() ; i!= problem->nend() ; i++) {
707+
for (int k = 0; k < problem->serverTypeCount(); ++k) {
708+
capa += solver->get_solution(problem->rankX(*i, k)) * problem->getServer(k)->getMaxConnections();
709+
}
710+
}
711+
//Display spare capacity.
712+
double avg_spare_capa;
713+
for (int s = 1; s < problem->stageCount(); ++s) {
714+
double clients = 0;
715+
for(NodeIterator i = problem->nbegin() ; i!= problem->nend() ; i++) {
716+
clients += solver->get_solution(problem->rankY(*i, s));
717+
}
718+
out.precision(2);
719+
double spare_capa = (capa-clients)/capa;
720+
avg_spare_capa += spare_capa;
721+
out << "d SPARE_CAPA_S" << s << " " << fixed << spare_capa <<endl;
722+
}
723+
avg_spare_capa /= problem->groupCount();
724+
out << "d SPARE_CAPA " << fixed << avg_spare_capa <<endl;
725+
}
704726

705727

706728

src/glpk_solver.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,6 @@ class glpk_solver: public abstract_solver, public scoeff_solver<double, 1, 1> {
7979
int end_add_constraints(void);
8080

8181
glp_prob *lp; // internal solver representation
82-
//CUDFVersionedPackageList *all_versioned_packages; // list of all versioned packages
8382
int nb_packages; // number of packages
8483

8584
CUDFcoefficient *lb, *ub; // arrays of lower and upper bounds

src/scoeff_solver.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
#include <vector>
1414
#include <stdlib.h>
1515
#include <stdio.h>
16-
//#include <cudf.h>
16+
1717

1818
// Template to allow coefficient saving
1919
// mainly used to save objective coefficients

0 commit comments

Comments
 (0)