Skip to content

Commit e298ac6

Browse files
committed
Fix computation of expected #children + add XCSP messages (#25)
1 parent ddbee3d commit e298ac6

File tree

5 files changed

+62
-40
lines changed

5 files changed

+62
-40
lines changed

src/cplex_solver.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,9 @@ abstract_solver *new_cplex_solver() { return new cplex_solver(); }
1818
// requires the list of versioned packages and the total amount of variables (including additional ones)
1919
int cplex_solver::init_solver(PSLProblem *problem, int other_vars) {
2020
int status;
21-
solution_count = 0;
22-
node_count = 0;
23-
time_count = 0;
21+
_solutionCount = 0;
22+
_nodeCount = 0;
23+
_timeCount = 0;
2424

2525
// Coefficient initialization
2626
initialize_coeffs(problem->rankCount() + other_vars);
@@ -188,9 +188,9 @@ int cplex_solver::solve() {
188188
stime += time(NULL);
189189
// Get solution status
190190
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);
191+
_solutionCount += CPXgetsolnpoolnumsolns(env, lp) + CPXgetsolnpoolnumreplaced(env, lp);
192+
_timeCount += stime;
193+
_nodeCount += CPXgetnodecnt(env, lp);
194194
if (i < nb_objectives - 1) {
195195
// Get next non empty objective
196196
// (must be done here to avoid conflicting method calls

src/cplex_solver.h

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -84,13 +84,13 @@ class cplex_solver: public abstract_solver, public scoeff_solver<double, 0, 0> {
8484
CUDFcoefficient get_solution(int k);
8585

8686
// get the number of solutions found at the end of solving
87-
int solutionCount(){return solution_count;}
87+
int solutionCount(){return _solutionCount;}
8888
// get the number of objectives (or sub-problems).
8989
int objectiveCount();
9090
// get the number of nodes at the end of solving
91-
int nodeCount() {return node_count;}
91+
int nodeCount() {return _nodeCount;}
9292
// get the solving time.
93-
int timeCount() {return time_count;}
93+
int timeCount() {return _timeCount;}
9494

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

116116
private:
117-
int solution_count;
118-
int node_count;
119-
double time_count;
117+
int _solutionCount;
118+
int _nodeCount;
119+
double _timeCount;
120120

121121
};
122122

src/cudf.c

Lines changed: 22 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,10 @@
1616

1717

1818

19-
//Remove main
19+
PSLProblem* current_problem = NULL;
20+
PSLProblem* the_problem = NULL;
21+
22+
int verbosity = DEFAULT;
2023

2124

2225
template <typename T>
@@ -57,7 +60,7 @@ void print_help() {
5760
"MANCOOSI project, grant agreement n. 214898.\n");
5861
fprintf(
5962
stderr,
60-
"Usual call: mccs -i <input_file> -o <outputfile> <criteria combiner>[<criteria>{, <criteria>}*] <solver option> <other options>?\n");
63+
"Usual call: opossum -i <input_file> -o <outputfile> <criteria combiner>[<criteria>{, <criteria>}*] <solver option> <other options>?\n");
6164
fprintf(stderr, "file options:\n");
6265
fprintf(
6366
stderr,
@@ -536,12 +539,11 @@ int main(int argc, char *argv[]) {
536539
if (verbosity >= VERBOSE) {
537540
print_generator_summary(out, the_problem);
538541
export_problem(the_problem);
539-
if (verbosity >= ALL) {
540-
print_problem(out, the_problem);
541-
}
542+
print_problem(out, the_problem);
542543
out << "================================================================" << endl;
543544
}
544545

546+
545547
// choose the solver
546548
if (solver == (abstract_solver *)NULL)
547549
#ifdef USECPLEX
@@ -585,6 +587,7 @@ int main(int argc, char *argv[]) {
585587
if(verbosity >= QUIET) {
586588
if(verbosity >= DEFAULT) {
587589
out << "================================================================" << endl;
590+
//out << "c " << solver->objectiveCount() << " OBJECTIVES " << obj_descr << endl;
588591
}
589592
out << "s OPTIMAL" << endl;
590593
out << "o " << obj << endl;
@@ -613,12 +616,6 @@ int main(int argc, char *argv[]) {
613616
exit(0);
614617
}
615618

616-
PSLProblem* current_problem = NULL;
617-
PSLProblem* the_problem = NULL;
618-
619-
int verbosity = DEFAULT;
620-
//bool showID=false;
621-
622619
int parse_pslp(istream& in)
623620
{
624621
if(the_problem) delete the_problem;
@@ -634,7 +631,18 @@ int parse_pslp(istream& in)
634631
void print_problem(ostream& out, PSLProblem *problem)
635632
{
636633
out << "================================================================" << endl;
637-
if (problem->getRoot())
634+
out << "c " << problem->groupCount() << " GROUPS "
635+
<< problem->facilityTypeCount() << " FTYPES "
636+
<< problem->levelTypeCount() << " LEVELS "
637+
<< endl
638+
<< "d FACILITIES " << problem->nodeCount() << endl
639+
<< "d CLIENTS " << problem->clientCount() << endl
640+
<<endl ;
641+
;
642+
//TODO Set by groups
643+
//TODO Always display the total number of pserv and sum vector of pservs
644+
if (verbosity >= ALL && problem->getRoot())
645+
out << endl;
638646
problem->getRoot()->print(out);
639647
}
640648

@@ -648,7 +656,7 @@ extern void export_problem(PSLProblem *problem)
648656
extern void print_generator_summary(ostream & out, PSLProblem *problem)
649657
{
650658
out << "================================================================" << endl;
651-
problem->printGeneratorSummary(out);
659+
problem->print_generator(out);
652660
out << "================================================================" << endl;
653661
out << *problem;
654662
}
@@ -700,7 +708,7 @@ void print_messages(ostream & out, PSLProblem *problem, abstract_solver *solver)
700708
out << "d TIME " << solver->timeCount() << endl;
701709
out << "d NODES " << solver->nodeCount() << endl;
702710
out << "d SOLUTIONS " << solver->solutionCount() << endl;
703-
out << "d #OBJECTIVES " << solver->objectiveCount() << endl;
711+
out << "c #OBJECTIVES " << solver->objectiveCount() << endl;
704712
//Compute total pserver capacity
705713
double capa = 0;
706714
for(NodeIterator i = problem->nbegin() ; i!= problem->nend() ; i++) {

src/network.cpp

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ void FacilityNode::print(ostream& out) {
108108
string shift = string(2 * type->getLevel(), ' ');
109109
string sep = string(15, '-');
110110
if (children.size() > 0) {
111-
out << shift << children.size() << " " << sep << endl;
111+
out << shift << sep << " " << children.size() << endl;
112112
for (size_t i = 0; i < children.size(); ++i) {
113113
out << shift << *children[i] << endl;
114114
}
@@ -221,31 +221,32 @@ istream & FacilityType::read(istream & in, const PSLProblem& problem) {
221221
// PSLProblem Implementation
222222
//----------------------------------------
223223

224-
ostream& PSLProblem::printGeneratorSummary(ostream& out) {
225-
double expNodes[levelCount()];
226-
double expTreeSize[levelCount()];
227-
double expClients[levelCount()];
228-
double expCTreeSize[levelCount()];
229-
for (int l = 0; l < levelCount(); ++l) {
224+
ostream& PSLProblem::print_generator(ostream& out) {
225+
const int n = levelTypeCount();
226+
double expNodes[n];
227+
double expTreeSize[n];
228+
double expClients[n];
229+
double expCTreeSize[n];
230+
for (int l = 0; l < n; ++l) {
230231
expNodes[l]=0;
231232
expTreeSize[l]=0;
232233
expClients[l]=0;
233234
expCTreeSize[l]=0;
234235
}
235236
for (FacilityTypeListIterator f = facilities.begin(); f != facilities.end(); ++f) {
236-
int exp = (*f)->binoN() * (*f)->binoP();
237+
double exp = (*f)->binoP() * ( (double) (*f)->binoN());
237238
expNodes[(*f)->getLevel()] += exp;
238239
expClients[(*f)->getLevel()] += exp * (*f)->getTotalDemand();
239240
}
240-
expTreeSize[levelCount()-1] = 0;
241-
expCTreeSize[levelCount()-1] = 0;
242-
for (int l = levelCount() -2; l >= 0; --l) {
241+
expTreeSize[n-1] = 0;
242+
expCTreeSize[n-1] = 0;
243+
for (int l = n -2; l >= 0; --l) {
243244
expTreeSize[l] = (expTreeSize[l+1] + 1) * expNodes[l+1];
244245
expCTreeSize[l] = (expCTreeSize[l+1]) * expNodes[l+1] + expClients[l + 1];
245246
}
246247

247248
out << "Expected:" << endl << "Level: #children - #child-clients - |subtree| - #subtree-clients" << endl;
248-
for (int l = 0; l < levelCount()-1; ++l) {
249+
for (int l = 0; l < n-1; ++l) {
249250
out << l << ": " << expNodes[l+1] << "\t" << expClients[l+1] << "\t" << expTreeSize[l] << "\t" << expCTreeSize[l] << endl;
250251
}
251252
out << "Total Facilities: " << (expTreeSize[0]+ expNodes[0]) <<endl;
@@ -265,6 +266,7 @@ FacilityNode* PSLProblem::generateNetwork(bool hierarchic) {
265266
levelNodeCounts.push_back(1);
266267
queue<FacilityNode*> queue;
267268
root = new FacilityNode(_nodeCount++, facilities[0]);
269+
_clientCount += facilities[0]->getTotalDemand();
268270
queue.push(root);
269271
unsigned int ftype = 1, clevel = 0, idx = 0;
270272
FacilityNode* current = queue.front();
@@ -275,6 +277,7 @@ FacilityNode* PSLProblem::generateNetwork(bool hierarchic) {
275277
&& facilities[idx]->getLevel() == clevel + 1) {
276278
//number of children
277279
const unsigned int nbc = facilities[idx]->genRandomFacilities();
280+
_clientCount += nbc * facilities[idx]->getTotalDemand();
278281
//generate children
279282
for (unsigned int i = 0; i < nbc; ++i) {
280283
FacilityNode* child = new FacilityNode(_nodeCount,
@@ -535,6 +538,7 @@ ostream& operator <<(ostream & out, const PSLProblem & f) {
535538
cout << "}" << endl << "Servers: ";
536539
transform(f.servers.begin(), f.servers.end(),
537540
ostream_iterator<ServerType>(out, " "), dereference<ServerType>);
541+
out << endl << "Facilities:" << endl;
538542
transform(f.facilities.begin(), f.facilities.end(),
539543
ostream_iterator<FacilityType>(out, "\n"),
540544
dereference<FacilityType>);

src/network.hpp

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -557,7 +557,7 @@ class PathIterator : public std::iterator<std::forward_iterator_tag, pair<Facili
557557

558558
class PSLProblem {
559559
public:
560-
PSLProblem() : _groupCount(0), root(NULL), _nodeCount(0) {}
560+
PSLProblem() : _groupCount(0), root(NULL), _nodeCount(0), _clientCount(0) {}
561561

562562
//Destructor of PSLProblem
563563
//Delete all nodes of the tree
@@ -591,13 +591,17 @@ class PSLProblem {
591591
return facilities.size();
592592
}
593593

594+
inline unsigned int levelTypeCount() const {
595+
return facilities[facilities.size()-1]->getLevel() + 1;
596+
}
597+
594598
inline unsigned int levelCount() const {
595599
return levelNodeCounts.size();
596600
}
597601

598602
void setSeed(const unsigned int seed);
599603

600-
ostream& printGeneratorSummary(ostream& out);
604+
ostream& print_generator(ostream& out);
601605

602606
FacilityNode* generateNetwork();
603607
//generate Breadth-First Numbered Tree
@@ -617,6 +621,10 @@ class PSLProblem {
617621
return _nodeCount - 1;
618622
}
619623

624+
inline unsigned int clientCount() const {
625+
return _clientCount;
626+
}
627+
620628
inline unsigned int pathCount() const {
621629
return lengthCumulPathCounts.back();
622630
}
@@ -734,6 +742,7 @@ class PSLProblem {
734742
levelCumulNodeCounts.clear();
735743
lengthCumulPathCounts.clear();
736744
_nodeCount = 0;
745+
_clientCount = 0;
737746
if(node != NULL) {
738747
for ( size_t i = 0; i < node->getChildrenCount(); ++i ) {
739748
deleteTree(node->toChild(i)->getDestination());
@@ -750,6 +759,7 @@ class PSLProblem {
750759
unsigned int _groupCount;
751760
FacilityNode* root;
752761
unsigned int _nodeCount;
762+
unsigned int _clientCount;
753763
IntList levelNodeCounts;
754764
//number of nodes of level lower or equal than l;
755765
IntList levelCumulNodeCounts;

0 commit comments

Comments
 (0)