-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvehiculos.cpp
More file actions
114 lines (98 loc) · 2.89 KB
/
vehiculos.cpp
File metadata and controls
114 lines (98 loc) · 2.89 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
#include <iostream>
#include <vector>
#include <cmath>
#include "nodos.hpp"
#include "vehiculos.hpp"
using namespace std;
vehiculo::vehiculo(int i, int c) {
id = i;
capacidad = c;
demandaL = 0;
demandaB = 0;
distancia_recorrida = 0;
posicion = {0, 0};
ruta = {}; //vector de int => id's de nodos
}
void vehiculo::print() {
cout << "Vehiculo " << id << "\n"
<< " Capacidad: " << capacidad << "\n"
<< " Demanda Linehaul: " << demandaL << "\n"
<< " Demanda Backhaul: " << demandaB << "\n"
<< " Distancia Recorrida: " << distancia_recorrida << "\n"
<< " Pos: (" << posicion.at(0) << ", " << posicion.at(1) << ")" << "\n"
<< " Ruta: (";
for (const int i : ruta){
cout << i << " ";
}
cout << ")\n";
}
void vehiculo::add_ruta(int x) {
ruta.push_back(x);
}
void vehiculo::add_ruta_faltante(int x) {
ruta.pop_back();
ruta.push_back(x);
ruta.push_back(1);
}
void vehiculo::add_l(int x) {
demandaL += x;
}
void vehiculo::rem_l(int x) {
demandaL -= x;
}
void vehiculo::add_b(int x) {
demandaB += x;
}
void vehiculo::rem_b(int x) {
demandaB -= x;
}
void vehiculo::add_dist(double d) {
distancia_recorrida += d;
}
void vehiculo::set_pos(float x, float y) {
vector<float> p;
p.push_back(x);
p.push_back(y);
posicion = p;
}
double vehiculo::dist(nodo uno) {
double xs = pow(uno.coordX - posicion.at(0), 2);
double ys = pow(uno.coordY - posicion.at(1), 2);
double distancia = sqrt(xs + ys);
//cout << "xs: " << xs << " ys " << ys << " d " << distancia << endl;
return distancia;
}
bool vehiculo::recorrido_terminado() {
if (ruta.at(ruta.size() - 1) == 1 || ruta.empty()) {
return true;
} else {
return false;
}
}
//auxiliar para recalcular
double distancia_2nodos(float x1, float y1, float x2, float y2){
double xs = pow(x1 - x2, 2);
double ys = pow(y1 - y2, 2);
double distancia = sqrt(xs + ys);
return distancia;
}
void vehiculo::recalcularD(vector<nodo> nodos) {
if (!nodos.empty()) {
//el 1 no viene, se calcula como el primero y el ultimo
double d = distancia_2nodos(nodos.at(nodos.size()-1).coordX, nodos.at(nodos.size()-1).coordY, nodos.front().coordX, nodos.front().coordY);
//cout << "d: " << d << endl;
for (int i = 1; i < ruta.size(); ++i) {
float x1 = nodos.at(i).coordX;
float y1 = nodos.at(i).coordY;
float x2 = nodos.at(i-1).coordX;
float y2 = nodos.at(i-1).coordY;
d += distancia_2nodos(x1, y1, x2, y2);
//cout << "x1 " << x1
// << " y1 " << y1
// << " x2 " << x2
// << " y2 " << y2
// << " d: " << d << endl;
}
distancia_recorrida = d;
}
}