Skip to content

Commit

Permalink
Fix computation of expected #children + add XCSP messages (#25)
Browse files Browse the repository at this point in the history
  • Loading branch information
arnaud-m committed Jul 2, 2012
1 parent ddbee3d commit e298ac6
Show file tree
Hide file tree
Showing 5 changed files with 62 additions and 40 deletions.
12 changes: 6 additions & 6 deletions src/cplex_solver.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +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;
_solutionCount = 0;
_nodeCount = 0;
_timeCount = 0;

// Coefficient initialization
initialize_coeffs(problem->rankCount() + other_vars);
Expand Down Expand Up @@ -188,9 +188,9 @@ int cplex_solver::solve() {
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);
_solutionCount += CPXgetsolnpoolnumsolns(env, lp) + CPXgetsolnpoolnumreplaced(env, lp);
_timeCount += stime;
_nodeCount += CPXgetnodecnt(env, lp);
if (i < nb_objectives - 1) {
// Get next non empty objective
// (must be done here to avoid conflicting method calls
Expand Down
12 changes: 6 additions & 6 deletions src/cplex_solver.h
Original file line number Diff line number Diff line change
Expand Up @@ -84,13 +84,13 @@ class cplex_solver: public abstract_solver, public scoeff_solver<double, 0, 0> {
CUDFcoefficient get_solution(int k);

// get the number of solutions found at the end of solving
int solutionCount(){return solution_count;}
int solutionCount(){return _solutionCount;}
// 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;}
int nodeCount() {return _nodeCount;}
// get the solving time.
int timeCount() {return time_count;}
int timeCount() {return _timeCount;}

// variables only for internal use (should be private)
CPXENVptr env; // cplex environment
Expand All @@ -114,9 +114,9 @@ class cplex_solver: public abstract_solver, public scoeff_solver<double, 0, 0> {
}

private:
int solution_count;
int node_count;
double time_count;
int _solutionCount;
int _nodeCount;
double _timeCount;

};

Expand Down
36 changes: 22 additions & 14 deletions src/cudf.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,10 @@



//Remove main
PSLProblem* current_problem = NULL;
PSLProblem* the_problem = NULL;

int verbosity = DEFAULT;


template <typename T>
Expand Down Expand Up @@ -57,7 +60,7 @@ void print_help() {
"MANCOOSI project, grant agreement n. 214898.\n");
fprintf(
stderr,
"Usual call: mccs -i <input_file> -o <outputfile> <criteria combiner>[<criteria>{, <criteria>}*] <solver option> <other options>?\n");
"Usual call: opossum -i <input_file> -o <outputfile> <criteria combiner>[<criteria>{, <criteria>}*] <solver option> <other options>?\n");
fprintf(stderr, "file options:\n");
fprintf(
stderr,
Expand Down Expand Up @@ -536,12 +539,11 @@ int main(int argc, char *argv[]) {
if (verbosity >= VERBOSE) {
print_generator_summary(out, the_problem);
export_problem(the_problem);
if (verbosity >= ALL) {
print_problem(out, the_problem);
}
print_problem(out, the_problem);
out << "================================================================" << endl;
}


// choose the solver
if (solver == (abstract_solver *)NULL)
#ifdef USECPLEX
Expand Down Expand Up @@ -585,6 +587,7 @@ int main(int argc, char *argv[]) {
if(verbosity >= QUIET) {
if(verbosity >= DEFAULT) {
out << "================================================================" << endl;
//out << "c " << solver->objectiveCount() << " OBJECTIVES " << obj_descr << endl;
}
out << "s OPTIMAL" << endl;
out << "o " << obj << endl;
Expand Down Expand Up @@ -613,12 +616,6 @@ int main(int argc, char *argv[]) {
exit(0);
}

PSLProblem* current_problem = NULL;
PSLProblem* the_problem = NULL;

int verbosity = DEFAULT;
//bool showID=false;

int parse_pslp(istream& in)
{
if(the_problem) delete the_problem;
Expand All @@ -634,7 +631,18 @@ int parse_pslp(istream& in)
void print_problem(ostream& out, PSLProblem *problem)
{
out << "================================================================" << endl;
if (problem->getRoot())
out << "c " << problem->groupCount() << " GROUPS "
<< problem->facilityTypeCount() << " FTYPES "
<< problem->levelTypeCount() << " LEVELS "
<< endl
<< "d FACILITIES " << problem->nodeCount() << endl
<< "d CLIENTS " << problem->clientCount() << endl
<<endl ;
;
//TODO Set by groups
//TODO Always display the total number of pserv and sum vector of pservs
if (verbosity >= ALL && problem->getRoot())
out << endl;
problem->getRoot()->print(out);
}

Expand All @@ -648,7 +656,7 @@ extern void export_problem(PSLProblem *problem)
extern void print_generator_summary(ostream & out, PSLProblem *problem)
{
out << "================================================================" << endl;
problem->printGeneratorSummary(out);
problem->print_generator(out);
out << "================================================================" << endl;
out << *problem;
}
Expand Down Expand Up @@ -700,7 +708,7 @@ void print_messages(ostream & out, PSLProblem *problem, abstract_solver *solver)
out << "d TIME " << solver->timeCount() << endl;
out << "d NODES " << solver->nodeCount() << endl;
out << "d SOLUTIONS " << solver->solutionCount() << endl;
out << "d #OBJECTIVES " << solver->objectiveCount() << endl;
out << "c #OBJECTIVES " << solver->objectiveCount() << endl;
//Compute total pserver capacity
double capa = 0;
for(NodeIterator i = problem->nbegin() ; i!= problem->nend() ; i++) {
Expand Down
28 changes: 16 additions & 12 deletions src/network.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ void FacilityNode::print(ostream& out) {
string shift = string(2 * type->getLevel(), ' ');
string sep = string(15, '-');
if (children.size() > 0) {
out << shift << children.size() << " " << sep << endl;
out << shift << sep << " " << children.size() << endl;
for (size_t i = 0; i < children.size(); ++i) {
out << shift << *children[i] << endl;
}
Expand Down Expand Up @@ -221,31 +221,32 @@ istream & FacilityType::read(istream & in, const PSLProblem& problem) {
// PSLProblem Implementation
//----------------------------------------

ostream& PSLProblem::printGeneratorSummary(ostream& out) {
double expNodes[levelCount()];
double expTreeSize[levelCount()];
double expClients[levelCount()];
double expCTreeSize[levelCount()];
for (int l = 0; l < levelCount(); ++l) {
ostream& PSLProblem::print_generator(ostream& out) {
const int n = levelTypeCount();
double expNodes[n];
double expTreeSize[n];
double expClients[n];
double expCTreeSize[n];
for (int l = 0; l < n; ++l) {
expNodes[l]=0;
expTreeSize[l]=0;
expClients[l]=0;
expCTreeSize[l]=0;
}
for (FacilityTypeListIterator f = facilities.begin(); f != facilities.end(); ++f) {
int exp = (*f)->binoN() * (*f)->binoP();
double exp = (*f)->binoP() * ( (double) (*f)->binoN());
expNodes[(*f)->getLevel()] += exp;
expClients[(*f)->getLevel()] += exp * (*f)->getTotalDemand();
}
expTreeSize[levelCount()-1] = 0;
expCTreeSize[levelCount()-1] = 0;
for (int l = levelCount() -2; l >= 0; --l) {
expTreeSize[n-1] = 0;
expCTreeSize[n-1] = 0;
for (int l = n -2; l >= 0; --l) {
expTreeSize[l] = (expTreeSize[l+1] + 1) * expNodes[l+1];
expCTreeSize[l] = (expCTreeSize[l+1]) * expNodes[l+1] + expClients[l + 1];
}

out << "Expected:" << endl << "Level: #children - #child-clients - |subtree| - #subtree-clients" << endl;
for (int l = 0; l < levelCount()-1; ++l) {
for (int l = 0; l < n-1; ++l) {
out << l << ": " << expNodes[l+1] << "\t" << expClients[l+1] << "\t" << expTreeSize[l] << "\t" << expCTreeSize[l] << endl;
}
out << "Total Facilities: " << (expTreeSize[0]+ expNodes[0]) <<endl;
Expand All @@ -265,6 +266,7 @@ FacilityNode* PSLProblem::generateNetwork(bool hierarchic) {
levelNodeCounts.push_back(1);
queue<FacilityNode*> queue;
root = new FacilityNode(_nodeCount++, facilities[0]);
_clientCount += facilities[0]->getTotalDemand();
queue.push(root);
unsigned int ftype = 1, clevel = 0, idx = 0;
FacilityNode* current = queue.front();
Expand All @@ -275,6 +277,7 @@ FacilityNode* PSLProblem::generateNetwork(bool hierarchic) {
&& facilities[idx]->getLevel() == clevel + 1) {
//number of children
const unsigned int nbc = facilities[idx]->genRandomFacilities();
_clientCount += nbc * facilities[idx]->getTotalDemand();
//generate children
for (unsigned int i = 0; i < nbc; ++i) {
FacilityNode* child = new FacilityNode(_nodeCount,
Expand Down Expand Up @@ -535,6 +538,7 @@ ostream& operator <<(ostream & out, const PSLProblem & f) {
cout << "}" << endl << "Servers: ";
transform(f.servers.begin(), f.servers.end(),
ostream_iterator<ServerType>(out, " "), dereference<ServerType>);
out << endl << "Facilities:" << endl;
transform(f.facilities.begin(), f.facilities.end(),
ostream_iterator<FacilityType>(out, "\n"),
dereference<FacilityType>);
Expand Down
14 changes: 12 additions & 2 deletions src/network.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -557,7 +557,7 @@ class PathIterator : public std::iterator<std::forward_iterator_tag, pair<Facili

class PSLProblem {
public:
PSLProblem() : _groupCount(0), root(NULL), _nodeCount(0) {}
PSLProblem() : _groupCount(0), root(NULL), _nodeCount(0), _clientCount(0) {}

//Destructor of PSLProblem
//Delete all nodes of the tree
Expand Down Expand Up @@ -591,13 +591,17 @@ class PSLProblem {
return facilities.size();
}

inline unsigned int levelTypeCount() const {
return facilities[facilities.size()-1]->getLevel() + 1;
}

inline unsigned int levelCount() const {
return levelNodeCounts.size();
}

void setSeed(const unsigned int seed);

ostream& printGeneratorSummary(ostream& out);
ostream& print_generator(ostream& out);

FacilityNode* generateNetwork();
//generate Breadth-First Numbered Tree
Expand All @@ -617,6 +621,10 @@ class PSLProblem {
return _nodeCount - 1;
}

inline unsigned int clientCount() const {
return _clientCount;
}

inline unsigned int pathCount() const {
return lengthCumulPathCounts.back();
}
Expand Down Expand Up @@ -734,6 +742,7 @@ class PSLProblem {
levelCumulNodeCounts.clear();
lengthCumulPathCounts.clear();
_nodeCount = 0;
_clientCount = 0;
if(node != NULL) {
for ( size_t i = 0; i < node->getChildrenCount(); ++i ) {
deleteTree(node->toChild(i)->getDestination());
Expand All @@ -750,6 +759,7 @@ class PSLProblem {
unsigned int _groupCount;
FacilityNode* root;
unsigned int _nodeCount;
unsigned int _clientCount;
IntList levelNodeCounts;
//number of nodes of level lower or equal than l;
IntList levelCumulNodeCounts;
Expand Down

0 comments on commit e298ac6

Please sign in to comment.