-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathglobal.h
More file actions
119 lines (92 loc) · 3.81 KB
/
Copy pathglobal.h
File metadata and controls
119 lines (92 loc) · 3.81 KB
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
#ifndef UTILS_H
#define UTILS_H
#include <bits/stdc++.h>
#include <fstream>
struct individuo
{
// Lista de movimientos (heurísticas codificadas)
std::vector<int> moves;
// Funciones objetivo
int fobj[2];
};
struct hyperparams{
float pmyo;
float pmut; //Probabilidad que se realice mutacion
//Probabilidades individuales para cada mutación (la idea es que sumen 1)
float pmut_swap;
float pmut_inversion;
float pmut_intFlip;
float pcross; //Probabilidad que se realice cross over
int popsize;
int max_gen;
int n_heu;//Cantidad de heurísticas
int elite;
};
struct debug_params{
bool save_pops;
bool show_initial_yard;
};
struct write_files{
std::ofstream f_all_pops;
std::ofstream f_best_ind;
std::ofstream exec_params;
};
/* Reader functions */
void readInstance(std::ifstream &f, std::vector<std::vector<int>> &yard, std::vector<int> &stack_position);
/* Random functions */
void randomize(int seed);
int getRandomInt(int a, int b);
float getRandomProb();
float getRandomProb_lim(float lim);
/* Initialice functions */
individuo initialize_ind(std::vector<std::vector<int>> &initial_yard, std::vector<int> &stack_position);
std::vector<individuo> initialize_pop(std::vector<std::vector<int>> &initial_yard, std::vector<int> &stack_positions);
/*Heuristics*/
int RIL(std::vector<std::vector<int>> &yard, int origin_stack);
int RI(std::vector<std::vector<int>> &yard, int origin_stack);
int RI_R(std::vector<std::vector<int>> &yard, int origin_stack);
int RIL_R(std::vector<std::vector<int>> &yard, int origin_stack);
int myopic_space(std::vector<std::vector<int>> &yard, int origin_stack);
int myopic_min_space(std::vector<std::vector<int>> &yard, int origin_stack);
int RI_inverse(std::vector<std::vector<int>> &yard, int origin_stack);
int top_diff(std::vector<std::vector<int>> &yard, int origin_stack);
int apply_random_heuristic(std::vector<std::vector<int>> &yard, std::vector<int> &stack_position, int origin_stack);
/*Evolutive Algorithm functions*/
std::vector<individuo> one_point_crossover(individuo padre1, individuo padre2);
std::vector<individuo> opc(individuo &padre1, individuo &padre2);
std::vector<individuo> two_point_crossover(individuo padre1, individuo padre2);
std::vector<individuo> tpc(individuo &padre1, individuo &padre2);
void swap(individuo &ind);
void inversion(individuo &ind);
void intFlip(individuo &ind);
void mutatePop(std::vector<individuo> &pop);
void evaluateInd(individuo &ind, std::vector<std::vector<int>> &yard, std::vector<int> &stack_position);
void evaluatePop(std::vector<individuo> &pop, std::vector<std::vector<int>> &initial_yard, std::vector<int> &stack_position);
void generateNewPop(std::vector<individuo> &old_pop);
/* Extra functions */
void printYard(std::vector<std::vector<int>> &yard);
void printInd(individuo &ind);
std::tuple<int,int,int> search_next_c(std::vector<std::vector<int>> &yard);
bool desc_sort(std::pair<int, int>& a, std::pair<int, int>& b);
bool compararPorFobjAsc(const individuo &a, individuo &b);
/* file functions */
void writeIndDecoded(std::vector<std::vector<int>> &yard, std::vector<int> &stack_position, individuo &ind, std::ofstream &f);
void writeInd(individuo &ind, std::ofstream &f);
void writePob(int n_gen_actual, std::vector<individuo>& pop, std::ofstream &f);
/* ------------- VARIABLES GLOBALES ---------------------*/
// Declaramos variables globales de la instancia
extern std::string instance_name;
extern int n_bays;
extern int n_rows;
extern int max_h;
extern int n_initial_containers;
extern std::vector<std::vector<int>> initial_yard;
extern std::vector<int> stack_position;
//declaramos los hiperparametros
extern hyperparams params;
extern debug_params debug;
//Declaramos los archivos
extern write_files files;
// Declaramos el generador aleatoreo
extern std::mt19937 rng;
#endif