Skip to content

Commit

Permalink
removed stagnation_measure as configuration parameter of AntColonyCon…
Browse files Browse the repository at this point in the history
…figuration. it is now sufficient to call get_variation_coeffient resp. get_lambda_branching_factor between iterations.
  • Loading branch information
thomas.hammerl committed Mar 2, 2009
1 parent dc0f73d commit 1c351cf
Show file tree
Hide file tree
Showing 11 changed files with 69 additions and 114 deletions.
29 changes: 7 additions & 22 deletions acotemplate/trunk/include/libaco/ants.h
Original file line number Diff line number Diff line change
Expand Up @@ -247,16 +247,12 @@ class AntColonyConfiguration {
public:
enum LocalSearchType { LS_NONE, LS_ITERATION_BEST, LS_ALL };

enum StagnationMeasureType { STAG_NONE, STAG_VARIATION_COEFFICIENT, STAG_LAMBDA_BRANCHING_FACTOR };

/// Number of ants that construct a tour in every iteration.
unsigned int number_of_ants;
/// Weight of pheromone value in tour construction.
double alpha;
/// Weight of heuristic information in tour construction.
double beta;
/// Defines whether the stagnation measure shall be computed.
StagnationMeasureType stagnation_measure;
/// Defines how fast pheromone shall evaporate.
double evaporation_rate;
/// The initial amount of pheromone deposited on the edges.
Expand Down Expand Up @@ -384,22 +380,12 @@ template<class T=Ant, class P=PheromoneMatrix> class AntColony {
return pheromones_->average_lambda_branching_factor(0.05);
}

void update_stagnation_measure() {
if(stagnation_measure_type_ == AntColonyConfiguration::STAG_VARIATION_COEFFICIENT) {
stagnation_measure_ = compute_variation_coefficient();
} else if(stagnation_measure_type_ == AntColonyConfiguration::STAG_LAMBDA_BRANCHING_FACTOR) {
stagnation_measure_ = compute_lambda_branching_factor();
}
}

virtual void update_pheromones() = 0;
protected:
P *pheromones_;
double alpha_;
double beta_;
AntColonyConfiguration::LocalSearchType local_search_type_;
AntColonyConfiguration::StagnationMeasureType stagnation_measure_type_;
double stagnation_measure_;
std::list<T> *ants_;
OptimizationProblem *problem_;
T *best_so_far_;
Expand All @@ -415,8 +401,6 @@ template<class T=Ant, class P=PheromoneMatrix> class AntColony {
alpha_ = config.alpha;
beta_ = config.beta;
local_search_type_ = config.local_search;
stagnation_measure_type_ = config.stagnation_measure;
stagnation_measure_ = 0.0;
best_so_far_ = new T(problem->get_max_tour_size());
best_iteration_ = new T(problem->get_max_tour_size());
best_so_far_no_ls_ = new T(problem->get_max_tour_size());
Expand All @@ -434,15 +418,12 @@ template<class T=Ant, class P=PheromoneMatrix> class AntColony {
};

void run() {
reset_ants();
construct_ants_solutions();
update_best_tours_no_ls();
apply_local_search();
update_best_tours();
if(stagnation_measure_type_ != AntColonyConfiguration::STAG_NONE) {
update_stagnation_measure();
}
update_pheromones();
reset_ants();
}

std::vector<unsigned int> get_best_tour() {
Expand Down Expand Up @@ -477,8 +458,12 @@ template<class T=Ant, class P=PheromoneMatrix> class AntColony {
return best_iteration_no_ls_->get_tour_length();
}

double get_stagnation_measure() {
return stagnation_measure_;
double get_variation_coefficient() {
return compute_variation_coefficient();
}

double get_lambda_branching_factor() {
return compute_lambda_branching_factor();
}
};

Expand Down
Binary file modified acotemplate/trunk/lib/libaco.a
Binary file not shown.
22 changes: 14 additions & 8 deletions acotemplate/trunk/src/acotemplate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,16 @@
#include <tclap/CmdLine.h>
#include <acotemplate/template.h>

enum StagnationMeasureType { STAG_NONE, STAG_VARIATION_COEFFICIENT, STAG_LAMBDA_BRANCHING_FACTOR };

static unsigned int ants = 10;
static unsigned int iterations = UINT_MAX;
static double alpha = 1.0;
static double beta = 1.0;
static double rho = 0.1;
static double initial_pheromone = 0.1;
static bool print_tour_flag = false;
static AntColonyConfiguration::StagnationMeasureType stagnation_measure = AntColonyConfiguration::STAG_NONE;
static StagnationMeasureType stagnation_measure = STAG_NONE;
static double time_limit = DBL_MAX;
static bool simple_as_flag = false;
static bool elitist_as_flag = false;
Expand Down Expand Up @@ -106,17 +108,16 @@ static void parse_options(int argc, char *argv[]) {
acs_xi = acs_xi_arg.getValue();

if(stag_variance_arg.isSet()) {
stagnation_measure = AntColonyConfiguration::STAG_VARIATION_COEFFICIENT;
stagnation_measure = STAG_VARIATION_COEFFICIENT;
} else if(stag_lambda_arg.isSet()) {
stagnation_measure = AntColonyConfiguration::STAG_LAMBDA_BRANCHING_FACTOR;
stagnation_measure = STAG_LAMBDA_BRANCHING_FACTOR;
}
}

static void set_config(AntColonyConfiguration &config) {
config.number_of_ants = ants;
config.alpha = alpha;
config.beta = beta;
config.stagnation_measure = stagnation_measure;
config.evaporation_rate = rho;
config.initial_pheromone = initial_pheromone;
}
Expand Down Expand Up @@ -202,7 +203,7 @@ int main(int argc, char *argv[]) {
colony = get_ant_colony(problem);

std::cout << "iter\ttime\tbest\tbest_it";
std::cout << ((stagnation_measure != AntColonyConfiguration::STAG_NONE) ? "\tstagnation" : "");
std::cout << ((stagnation_measure != STAG_NONE) ? "\tstagnation" : "");
std::cout << (print_tour_flag ? "\tordering" : "");
std::cout << std::endl;
timer();
Expand All @@ -211,9 +212,14 @@ int main(int argc, char *argv[]) {
std::cout << (i+1) << "\t";
std::cout << timer() << "\t";
std::cout << colony->get_best_tour_length() << "\t";
std::cout << colony->get_best_tour_length_in_iteration();
if(stagnation_measure != AntColonyConfiguration::STAG_NONE) {
std::cout << colony->get_stagnation_measure();
std::cout << colony->get_best_tour_length_in_iteration() << "\t";

if(stagnation_measure == STAG_VARIATION_COEFFICIENT) {
std::cout << colony->get_variation_coefficient();
}

if(stagnation_measure == STAG_LAMBDA_BRANCHING_FACTOR) {
std::cout << colony->get_lambda_branching_factor();
}

if(print_tour_flag) {
Expand Down
29 changes: 7 additions & 22 deletions acotreewidth/trunk/include/libaco/ants.h
Original file line number Diff line number Diff line change
Expand Up @@ -247,16 +247,12 @@ class AntColonyConfiguration {
public:
enum LocalSearchType { LS_NONE, LS_ITERATION_BEST, LS_ALL };

enum StagnationMeasureType { STAG_NONE, STAG_VARIATION_COEFFICIENT, STAG_LAMBDA_BRANCHING_FACTOR };

/// Number of ants that construct a tour in every iteration.
unsigned int number_of_ants;
/// Weight of pheromone value in tour construction.
double alpha;
/// Weight of heuristic information in tour construction.
double beta;
/// Defines whether the stagnation measure shall be computed.
StagnationMeasureType stagnation_measure;
/// Defines how fast pheromone shall evaporate.
double evaporation_rate;
/// The initial amount of pheromone deposited on the edges.
Expand Down Expand Up @@ -384,22 +380,12 @@ template<class T=Ant, class P=PheromoneMatrix> class AntColony {
return pheromones_->average_lambda_branching_factor(0.05);
}

void update_stagnation_measure() {
if(stagnation_measure_type_ == AntColonyConfiguration::STAG_VARIATION_COEFFICIENT) {
stagnation_measure_ = compute_variation_coefficient();
} else if(stagnation_measure_type_ == AntColonyConfiguration::STAG_LAMBDA_BRANCHING_FACTOR) {
stagnation_measure_ = compute_lambda_branching_factor();
}
}

virtual void update_pheromones() = 0;
protected:
P *pheromones_;
double alpha_;
double beta_;
AntColonyConfiguration::LocalSearchType local_search_type_;
AntColonyConfiguration::StagnationMeasureType stagnation_measure_type_;
double stagnation_measure_;
std::list<T> *ants_;
OptimizationProblem *problem_;
T *best_so_far_;
Expand All @@ -415,8 +401,6 @@ template<class T=Ant, class P=PheromoneMatrix> class AntColony {
alpha_ = config.alpha;
beta_ = config.beta;
local_search_type_ = config.local_search;
stagnation_measure_type_ = config.stagnation_measure;
stagnation_measure_ = 0.0;
best_so_far_ = new T(problem->get_max_tour_size());
best_iteration_ = new T(problem->get_max_tour_size());
best_so_far_no_ls_ = new T(problem->get_max_tour_size());
Expand All @@ -434,15 +418,12 @@ template<class T=Ant, class P=PheromoneMatrix> class AntColony {
};

void run() {
reset_ants();
construct_ants_solutions();
update_best_tours_no_ls();
apply_local_search();
update_best_tours();
if(stagnation_measure_type_ != AntColonyConfiguration::STAG_NONE) {
update_stagnation_measure();
}
update_pheromones();
reset_ants();
}

std::vector<unsigned int> get_best_tour() {
Expand Down Expand Up @@ -477,8 +458,12 @@ template<class T=Ant, class P=PheromoneMatrix> class AntColony {
return best_iteration_no_ls_->get_tour_length();
}

double get_stagnation_measure() {
return stagnation_measure_;
double get_variation_coefficient() {
return compute_variation_coefficient();
}

double get_lambda_branching_factor() {
return compute_lambda_branching_factor();
}
};

Expand Down
Binary file modified acotreewidth/trunk/lib/libaco.a
Binary file not shown.
22 changes: 14 additions & 8 deletions acotreewidth/trunk/src/acotreewidth.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
#include <tclap/CmdLine.h>
#include <acotreewidth/decomp.h>

enum StagnationMeasureType { STAG_NONE, STAG_VARIATION_COEFFICIENT, STAG_LAMBDA_BRANCHING_FACTOR };

static std::string filepath;
static bool hypergraph_flag;
static unsigned int ants = 10;
Expand All @@ -19,7 +21,7 @@ static double initial_pheromone = -1.0;
static unsigned int heuristic = 0;
static unsigned int graph_type = 0;
static bool print_tour_flag = false;
static AntColonyConfiguration::StagnationMeasureType stagnation_measure = AntColonyConfiguration::STAG_NONE;
static StagnationMeasureType stagnation_measure = STAG_NONE;
static double stag_limit = 0.0;
static double time_limit = DBL_MAX;
static bool simple_as_flag = false;
Expand Down Expand Up @@ -163,9 +165,9 @@ static void parse_options(int argc, char *argv[]) {
}

if(stag_variance_arg.isSet()) {
stagnation_measure = AntColonyConfiguration::STAG_VARIATION_COEFFICIENT;
stagnation_measure = STAG_VARIATION_COEFFICIENT;
} else if(stag_lambda_arg.isSet()) {
stagnation_measure = AntColonyConfiguration::STAG_LAMBDA_BRANCHING_FACTOR;
stagnation_measure = STAG_LAMBDA_BRANCHING_FACTOR;
}
stag_limit = stag_limit_arg.getValue();

Expand Down Expand Up @@ -216,7 +218,6 @@ static void set_config(AntColonyConfiguration &config) {
config.number_of_ants = ants;
config.alpha = alpha;
config.beta = beta;
config.stagnation_measure = stagnation_measure;
config.evaporation_rate = rho;
config.initial_pheromone = initial_pheromone;
config.local_search = local_search;
Expand Down Expand Up @@ -344,7 +345,7 @@ int main(int argc, char *argv[]) {
std::cout << ((local_search != AntColonyConfiguration::LS_NONE) ? "\tnols" : "");
std::cout << "\tbest_it";
std::cout << ((local_search != AntColonyConfiguration::LS_NONE) ? "\tit_nols" : "");
std::cout << ((stagnation_measure != AntColonyConfiguration::STAG_NONE) ? "\tstagnation" : "");
std::cout << ((stagnation_measure != STAG_NONE) ? "\tstagnation" : "");
std::cout << (print_tour_flag ? "\tordering" : "");
std::cout << std::endl;

Expand All @@ -371,10 +372,15 @@ int main(int argc, char *argv[]) {
if(local_search != AntColonyConfiguration::LS_NONE) {
std::cout << colony->get_best_tour_length_in_iteration_no_ls() << "\t";
}
if(stagnation_measure != AntColonyConfiguration::STAG_NONE) {
stag_value = colony->get_stagnation_measure();
std::cout << stag_value;

if(stagnation_measure == STAG_VARIATION_COEFFICIENT) {
std::cout << colony->get_variation_coefficient();
}

if(stagnation_measure == STAG_LAMBDA_BRANCHING_FACTOR) {
std::cout << colony->get_lambda_branching_factor();
}

if(print_tour_flag) {
std::cout << "\t";
print_tour(colony->get_best_tour_in_iteration());
Expand Down
29 changes: 7 additions & 22 deletions acotsp/trunk/include/libaco/ants.h
Original file line number Diff line number Diff line change
Expand Up @@ -247,16 +247,12 @@ class AntColonyConfiguration {
public:
enum LocalSearchType { LS_NONE, LS_ITERATION_BEST, LS_ALL };

enum StagnationMeasureType { STAG_NONE, STAG_VARIATION_COEFFICIENT, STAG_LAMBDA_BRANCHING_FACTOR };

/// Number of ants that construct a tour in every iteration.
unsigned int number_of_ants;
/// Weight of pheromone value in tour construction.
double alpha;
/// Weight of heuristic information in tour construction.
double beta;
/// Defines whether the stagnation measure shall be computed.
StagnationMeasureType stagnation_measure;
/// Defines how fast pheromone shall evaporate.
double evaporation_rate;
/// The initial amount of pheromone deposited on the edges.
Expand Down Expand Up @@ -384,22 +380,12 @@ template<class T=Ant, class P=PheromoneMatrix> class AntColony {
return pheromones_->average_lambda_branching_factor(0.05);
}

void update_stagnation_measure() {
if(stagnation_measure_type_ == AntColonyConfiguration::STAG_VARIATION_COEFFICIENT) {
stagnation_measure_ = compute_variation_coefficient();
} else if(stagnation_measure_type_ == AntColonyConfiguration::STAG_LAMBDA_BRANCHING_FACTOR) {
stagnation_measure_ = compute_lambda_branching_factor();
}
}

virtual void update_pheromones() = 0;
protected:
P *pheromones_;
double alpha_;
double beta_;
AntColonyConfiguration::LocalSearchType local_search_type_;
AntColonyConfiguration::StagnationMeasureType stagnation_measure_type_;
double stagnation_measure_;
std::list<T> *ants_;
OptimizationProblem *problem_;
T *best_so_far_;
Expand All @@ -415,8 +401,6 @@ template<class T=Ant, class P=PheromoneMatrix> class AntColony {
alpha_ = config.alpha;
beta_ = config.beta;
local_search_type_ = config.local_search;
stagnation_measure_type_ = config.stagnation_measure;
stagnation_measure_ = 0.0;
best_so_far_ = new T(problem->get_max_tour_size());
best_iteration_ = new T(problem->get_max_tour_size());
best_so_far_no_ls_ = new T(problem->get_max_tour_size());
Expand All @@ -434,15 +418,12 @@ template<class T=Ant, class P=PheromoneMatrix> class AntColony {
};

void run() {
reset_ants();
construct_ants_solutions();
update_best_tours_no_ls();
apply_local_search();
update_best_tours();
if(stagnation_measure_type_ != AntColonyConfiguration::STAG_NONE) {
update_stagnation_measure();
}
update_pheromones();
reset_ants();
}

std::vector<unsigned int> get_best_tour() {
Expand Down Expand Up @@ -477,8 +458,12 @@ template<class T=Ant, class P=PheromoneMatrix> class AntColony {
return best_iteration_no_ls_->get_tour_length();
}

double get_stagnation_measure() {
return stagnation_measure_;
double get_variation_coefficient() {
return compute_variation_coefficient();
}

double get_lambda_branching_factor() {
return compute_lambda_branching_factor();
}
};

Expand Down
Binary file modified acotsp/trunk/lib/libaco.a
Binary file not shown.
Loading

0 comments on commit 1c351cf

Please sign in to comment.