Skip to content

Commit

Permalink
First version of conn criteria (#10)
Browse files Browse the repository at this point in the history
Define template for the combiner factory (#10)
Add title to graphics (#18)
  • Loading branch information
arnaud-m committed Jun 14, 2012
1 parent 57b8cc2 commit 4fdd026
Show file tree
Hide file tree
Showing 10 changed files with 256 additions and 90 deletions.
8 changes: 6 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
#MILP Model
cplexpbs.lp
#Opossum files
cplexpb*.lp
cplexpb*.dot
cplexsol.xml
sol-*.dot

# c++ / cmake
*.o
/bin
Expand Down
82 changes: 82 additions & 0 deletions src/conn_criteria.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@

/*******************************************************/
/* CUDF solver: conn_criteria.h */
/* Implementation of the conn criteria */
/* (c) Arnaud Malapert I3S (UNSA-CNRS) 2012 */
/*******************************************************/


#include <conn_criteria.h>


// Criteria initialization
void conn_criteria::initialize(PSLProblem *problem, abstract_solver *solver) {
pslp_criteria::initialize(problem, solver);
stage_max = min(stage_range.second, problem->stageCount() - 1);
//TODO Initialize upper bound
}

// Computing the number of columns required to handle the criteria
int conn_criteria::set_variable_range(int first_free_var) {
return first_free_var;
}

int conn_criteria::rank(pair<FacilityNode*,FacilityNode*> const &path, const unsigned int stage)
{
return problem->rankZ(path, stage);
}
// Add the criteria to the current objective function
int conn_criteria::add_criteria_to_objective(CUDFcoefficient lambda) {
if(isInRange(0, length_range)) {
for (NodeIterator n = problem->getRoot()->nbegin(); n != problem->getRoot()->nend(); ++n) {
if(reliable != 0) { //local connections are reliable.
for (int s = stage_range.first; s <= stage_max; ++s) {
set_obj_coeff(problem->rankZ(*n, s), lambda);
}
}
}
}
for (PathIterator p = problem->getRoot()->pbegin(); p != problem->getRoot()->pend(); ++p) {
if(isInRL(*p)) {
for (int s = stage_range.first; s <= stage_max; ++s) {
set_obj_coeff(rank(*p, s), lambda);
}
}
}
return 0;
}

// Add the criteria to the constraint set
int conn_criteria::add_criteria_to_constraint(CUDFcoefficient lambda) {
if(isInRange(0, length_range)) {
for (NodeIterator n = problem->getRoot()->nbegin(); n != problem->getRoot()->nend(); ++n) {
if(reliable != 0) { //local connections are reliable.
for (int s = stage_range.first; s <= stage_max; ++s) {
set_constraint_coeff(problem->rankZ(*n, s), lambda);
}
}
}
}
for (PathIterator p = problem->getRoot()->pbegin(); p != problem->getRoot()->pend(); ++p) {
if(isInRL(*p)) {
for (int s = stage_range.first; s <= stage_max; ++s) {
set_constraint_coeff(rank(*p, s), lambda);
}
}
}
return 0;
}

int conn_criteria::add_constraints()
{
return 0;
}









65 changes: 65 additions & 0 deletions src/conn_criteria.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@

/*******************************************************/
/* CUDF solver: conn_criteria.h */
/* Concrete class for the conn criteria */
/* (c) Arnaud Malapert I3S (UNSA-CNRS) 2012 */
/*******************************************************/


#ifndef _CONN_CRITERIA_H_
#define _CONN_CRITERIA_H_

#include <abstract_criteria.h>

// A concrete class for the conn criteria
// i.e. the number of connections between a pserver and a client.
// the scope of connections can be retricted by using properties.
class conn_criteria: public pslp_criteria{
public:

pair<unsigned int, unsigned int> stage_range;
pair<unsigned int, unsigned int> length_range;

unsigned int stage_max;

conn_criteria(CUDFcoefficient lambda_crit, int reliable, pair<unsigned int, unsigned int> stage_range, pair<unsigned int, unsigned int> length_range) : pslp_criteria(lambda_crit, reliable), stage_range(stage_range), length_range(length_range) {};
virtual ~conn_criteria() {}


// Criteria initialization
void initialize(PSLProblem *problem, abstract_solver *solver);

// Allocate some columns for the criteria
int set_variable_range(int first_free_var);
// Add the criteria to the objective
int add_criteria_to_objective(CUDFcoefficient lambda);
// Add the criteria to the constraint set
int add_criteria_to_constraint(CUDFcoefficient lambda);
// Add constraints required by the criteria
int add_constraints();

int rank(pair<FacilityNode*, FacilityNode*> const &path, const unsigned int stage);

private :

inline bool isInRel(pair<FacilityNode*, FacilityNode*> const & path) {
if(reliable < 0) return true;
else {
const bool relp = isReliablePath(path.first, path.second);
return reliable == 0 ? !relp : relp;
}
}

inline bool isInLength(pair<FacilityNode*, FacilityNode*> const & path) {
return isInRange(path.second->getType()->getLevel() - path.first->getType()->getLevel(), length_range);
}

inline bool isInRL(pair<FacilityNode*, FacilityNode*> const &path) {
return isInRel(path) && isInLength(path);
}

};

#endif


1 change: 1 addition & 0 deletions src/criteria.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
#include <abstract_criteria.h>

#include <pserv_criteria.h>
#include <conn_criteria.h>

#include <lexagregate_combiner.h>
#include <agregate_combiner.h>
Expand Down
114 changes: 50 additions & 64 deletions src/cudf.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,18 @@

//Remove main
//#define main toto
#define C_TEXT( text ) ((char*)std::string( text ).c_str())
#define C_STR( text ) ((char*)std::string( text ).c_str())


template <typename T>
T* makeCombiner(CriteriaList* criteria, char* name) {
if (criteria->empty()) {
fprintf(stderr, "ERROR: -%s option requires a list of criteria.\n", name);
exit(-1);
}
return new T(criteria);

}
// underlying solver declaration
// allows using solvers withour having to include the whole solver classes

Expand Down Expand Up @@ -253,9 +263,9 @@ CUDFcoefficient get_criteria_lambda(char *crit_descr, unsigned int &pos, char si
}

void get_criteria_properties(char *crit_descr, unsigned int &pos,
string prop1, pair<unsigned int, unsigned int> &range1,
string prop2, pair<unsigned int, unsigned int> &range2,
int& reliable, CUDFcoefficient& lambda) {
string const & prop1, pair<unsigned int, unsigned int> &range1,
string const & prop2, pair<unsigned int, unsigned int> &range2,
int& reliable, CUDFcoefficient& lambda, char sign) {
int n = 0;
do {
vector< pair<unsigned int, unsigned int> *> opts;
Expand All @@ -272,6 +282,7 @@ void get_criteria_properties(char *crit_descr, unsigned int &pos,
}

} while(n > 0);
if(sign == '+') {lambda *=-1;}
cout << ">>>>>>>>>>> "<< prop1 <<": " << range1.first << " " << range1.second << endl;
cout << ">>>>>>>>>>> "<< prop2 <<": " << range2.first << " " << range2.second << endl;
cout << ">>>>>>>>>>> Reliable: " << reliable << endl;
Expand Down Expand Up @@ -504,14 +515,21 @@ CriteriaList *process_criteria(char *crit_descr, unsigned int &pos, bool first_l
int rel = -1;
CUDFcoefficient lambda = 1;
get_criteria_properties(crit_descr, pos,
C_TEXT("type"), r1,
C_TEXT("layer"), r2,
rel, lambda
"type", r1,
"layer", r2,
rel, lambda, crit_descr[sign]
);
if(crit_descr[sign] == '+') {lambda *=-1;}
criteria->push_back(new pserv_criteria(lambda, rel, r1, r2));
} else if (strncmp(crit_descr+crit_name, "conn", crit_name_length) == 0) {
//TODO conn_criteria
pair<unsigned int, unsigned int> r1(0, numeric_limits<int>::max()), r2(0,numeric_limits<int>::max() );
int rel = -1;
CUDFcoefficient lambda = 1;
get_criteria_properties(crit_descr, pos,
"stage", r1,
"length", r2,
rel, lambda, crit_descr[sign]
);
criteria->push_back(new conn_criteria(lambda, rel, r1, r2));
} else if (strncmp(crit_descr+crit_name, "bandw", crit_name_length) == 0) {
//TODO bandw_criteria
} else if (strncmp(crit_descr+crit_name, "agregate", crit_name_length) == 0) {
Expand Down Expand Up @@ -563,6 +581,7 @@ int main(int argc, char *argv[]) {
bool got_input = false;
bool got_output = false;
bool fulloutput = false;
char* obj_descr;
PSLProblem *problem;
vector<abstract_criteria *> criteria_with_property; //TODO Remove useless list ?
//TODO remove useless options;
Expand Down Expand Up @@ -617,76 +636,43 @@ int main(int argc, char *argv[]) {
;
} else if (strncmp(argv[i], "-lex[", 5) == 0) {
CriteriaList *criteria = get_criteria(argv[i]+4, true, &criteria_with_property);
if (criteria->size() > 0)
combiner = new lexicographic_combiner(criteria);
else {
fprintf(stderr, "ERROR: -lex option requires a list of criteria.\n");
exit(-1);
}
combiner = makeCombiner<lexicographic_combiner>(criteria, C_STR("lexicographic"));
obj_descr == argv[i];
} else if (strncmp(argv[i], "-lexicographic[", 15) == 0) {
CriteriaList *criteria = get_criteria(argv[i]+14, true, &criteria_with_property);
if (criteria->size() > 0)
combiner = new lexicographic_combiner(criteria);
else {
fprintf(stderr, "ERROR: -lexicographic option requires a list of criteria.\n");
exit(-1);
}
combiner = makeCombiner<lexicographic_combiner>(criteria, C_STR("lexicographic"));
obj_descr = argv[i];
cout << ">>>>>>>>>> " << argv[i] << endl;
cout << ">>>>>>>>>> " << obj_descr << endl;
} else if (strncmp(argv[i], "-agregate[", 10) == 0) {
CriteriaList *criteria = get_criteria(argv[i]+9, false, &criteria_with_property);
if (criteria->size() > 0)
combiner = new agregate_combiner(criteria);
else {
fprintf(stderr, "ERROR: -agregate option requires a list of criteria.\n");
exit(-1);
}
combiner = makeCombiner<agregate_combiner>(criteria, C_STR("agregate"));
obj_descr == argv[i];
} else if (strncmp(argv[i], "-lexagregate[", 13) == 0) {
CriteriaList *criteria = get_criteria(argv[i]+12, false, &criteria_with_property);
if (criteria->size() > 0)
combiner = new lexagregate_combiner(criteria);
else {
fprintf(stderr, "ERROR: -lexagregate option requires a list of criteria.\n");
exit(-1);
}
combiner = makeCombiner<lexagregate_combiner>(criteria, C_STR("lexagregate"));
obj_descr == argv[i];
} else if (strncmp(argv[i], "-lexsemiagregate[", 17) == 0) {
CriteriaList *criteria = get_criteria(argv[i]+16, false, &criteria_with_property);
if (criteria->size() > 0)
combiner = new lexsemiagregate_combiner(criteria);
else {
fprintf(stderr, "ERROR: -lexsemiagregate option requires a list of criteria.\n");
exit(-1);
}
combiner = makeCombiner<lexsemiagregate_combiner>(criteria, C_STR("lexsemiagregate"));
obj_descr == argv[i];

} else if (strncmp(argv[i], "-leximax[", 9) == 0) {
CriteriaList *criteria = get_criteria(argv[i]+8, false, &criteria_with_property);
if (criteria->size() > 0)
combiner = new leximax_combiner(criteria);
else {
fprintf(stderr, "ERROR: -leximax option requires a list of criteria.\n");
exit(-1);
}
combiner = makeCombiner<leximax_combiner>(criteria, C_STR("leximax"));
obj_descr == argv[i];
} else if (strncmp(argv[i], "-leximin[", 9) == 0) {
CriteriaList *criteria = get_criteria(argv[i]+8, false, &criteria_with_property);
if (criteria->size() > 0)
combiner = new leximin_combiner(criteria);
else {
fprintf(stderr, "ERROR: -leximin option requires a list of criteria.\n");
exit(-1);
}
combiner = makeCombiner<leximin_combiner>(criteria, C_STR("leximin"));
obj_descr == argv[i];
} else if (strncmp(argv[i], "-lexleximax[", 12) == 0) {
CriteriaList *criteria = get_criteria(argv[i]+11, false, &criteria_with_property);
if (criteria->size() > 0)
combiner = new lexleximax_combiner(criteria);
else {
fprintf(stderr, "ERROR: -lexleximax option requires a list of criteria.\n");
exit(-1);
}
combiner = makeCombiner<lexleximax_combiner>(criteria, C_STR("lexleximax"));
obj_descr == argv[i];
} else if (strncmp(argv[i], "-lexleximin[", 12) == 0) {
CriteriaList *criteria = get_criteria(argv[i]+11, false, &criteria_with_property);
if (criteria->size() > 0)
combiner = new lexleximin_combiner(criteria);
else {
fprintf(stderr, "ERROR: -lexleximin option requires a list of criteria.\n");
exit(-1);
}
combiner = makeCombiner<lexleximin_combiner>(criteria, C_STR("lexleximin"));
obj_descr == argv[i];
} else if (strcmp(argv[i], "-h") == 0) {
print_help();
exit(-1);
Expand Down Expand Up @@ -812,7 +798,7 @@ int main(int argc, char *argv[]) {
out << endl << "================================================================" << endl;
}
if(verbosity > 3) {
solution2dotty(*problem, *solver);
solution2dotty(*problem, *solver, obj_descr);
}

// print out additional informations
Expand Down
Loading

0 comments on commit 4fdd026

Please sign in to comment.