-
Notifications
You must be signed in to change notification settings - Fork 0
/
MainKnapsack.h
138 lines (83 loc) · 4.6 KB
/
MainKnapsack.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
#ifndef __KNAPSACK_STRUCT__
#define __KNAPSACK_STRUCT__
class MainKnapsack;
#include "LSStructure.h"
#include "AlternativeKnapsack.h"
extern list<set<int>> init_population;
extern string INFO;
extern int k_replication;
extern float Ta;
class MainKnapsack : public LSStructure{
protected:
float Backpack_capacity = 0; // capacity ofthe backpack
int n_items; // number of items
map<string, shared_ptr< AlternativeKnapsack > > dic_Alternative;
public :
vector< tuple<float, vector< float> > > Items_information; //information about each item : (key:weight : value:utility list for each criteria)
//constructor
MainKnapsack( shared_ptr< Evaluator > evaluator, int population_size_init, string filename, bool generate_population=false);
~MainKnapsack(){
for(map<string, shared_ptr< AlternativeKnapsack > > ::iterator it = dic_Alternative.begin(); it != dic_Alternative.end(); ++it){
dic_Alternative[(*it).first].reset();
dic_Alternative.erase((*it).first);
}
for(vector< tuple<float, vector< float> > >::iterator i = Items_information.begin(); i != Items_information.end(); ++i){
get<1>(*i).shrink_to_fit();
}
Items_information.shrink_to_fit();
};
//GETTERS
int get_n_items(){ return n_items; };
float get_weight_of(int i) { return std::get<0>(Items_information[i]); };
float get_utility(int i, int j) { return std::get<1>(Items_information[i])[j]; };
float get_capacity(){ return Backpack_capacity; };
//SETTERS
void set_WS_matrix(vector< vector< float > > new_ws){
n_objective = new_ws[0].size();
p_criteria = new_ws.size();
WS_matrix.resize(p_criteria);
for(int i = 0 ; i < p_criteria; i++)
WS_matrix[i] = new_ws[i];
};
vector< float > OPT_Alternative_PLNE(vector<float> WS_vector);
vector< float > get_extrem_points();
bool reached_limit(vector< float > extrem_point);
//READ FILES
// void readInitPopulationFile(string filename);
//RESOLUTION
bool Update_Archive(shared_ptr< Alternative > p, list< shared_ptr< Alternative > > &set_SOL);
bool Update_LocalArchive(shared_ptr< Alternative > p, list< string > &set_SOL);
bool Update_Archive(shared_ptr< Alternative > p, list< shared_ptr< Alternative > > &set_SOL, list<string> & population);
void update_alternatives(list< string > &set_Alt, bool Pareto);
void update_WS_matrix_Population();
void HYBRID_WS_PLS(double starting_time_sec, int ITER);
void HYBRID_PLS_WS(double starting_time_sec, int ITER);
void SWITCH_PLS_WS(double starting_time_sec, int ITER_PLS, int ITER_WS);
void MOLS_DYN_PSize(double starting_time_sec, vector< int > UB_Population, vector< string > Informations);
void MOLS_DYN_PSize_OS(double starting_time_sec, vector< int > UB_Population_list, vector< string > Informations);
void MOLS_DYN_INFO(double starting_time_sec, vector< int > UB_Population_list, vector< string > Informations);
void MOLS_DYN_MULTIPLE_PARAM(int Budget, vector< int > UB_Population_list, int inst_name, vector< string > Informations);
void MOLS_DYNAMIC(double starting_time_sec, vector< int > UB_Population_list, vector< string > Informations);
void MOLS_Cst_PSize(double starting_time_sec, int UB_Population_size);
void MOLS_local_Archive(double starting_time_sec);
void MOLS_Cst_PSize_RS(double starting_time_sec, int UB_Population_size);
void MOLS_Cst_PSize_OS(double starting_time_sec, int UB_Population_size);
void MOLS_OPT_PARAMETERS(double starting_time_sec, vector< map<string, float > > OPT_Params,
map<float,int> id_info, string information_file);
void MOLS_ML_RegLin(int Budget, vector<int> UB_Population_list, int inst_name, vector< float > Info_rate);
void Random_Selection(list< string > & dominated_solutions, list< string > & population, int upper_bound);
void Ordered_Selection(list< string > & dominated_solutions, list< string > & population, int upper_bound);
void LTA(list< string > & dominated_solutions, list< string > & population, int upper_bound);
void TA(list< string > & dominated_solutions, list< string > & population, int upper_bound);
//EVALUATION
void save_information(string filename, vector< float > criteria_vect, float time_cpu, int index);
void save_information(string filename, vector< float > criteria_vect, float time_cpu, int index, int ub);
//STATIC METHOD
static void Generate_random_Population(shared_ptr< Evaluator > evaluator, int number_of_individu);
void update_extrem_point(vector< float > extrem1, float & epsi, vector< float > point_eval, vector< float > & extrem2);
//functions to overload
void initializeInformation(shared_ptr< Evaluator > evaluator);
void MOLS(double starting_time_sec);
void GenerateInitialPopulation(int size_population);
};
#endif