-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathmixed_equ.cpp
152 lines (131 loc) · 3.47 KB
/
mixed_equ.cpp
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
139
140
141
142
143
144
145
146
147
148
149
150
151
152
#include <iostream>
#include <string>
#include <cstdio>
#include <cmath>
#include "func.h"
#include "data_struct.h"
#include "global_var.h"
#include "basic_util.h"
#include "shortest_path.h"
#include "dsd.h"
#include "frank_wolf.h"
#include "column_gen.h"
#include "save_data.h"
#include "load_data.h"
#include "show_status.h"
using namespace std;
static double trips[MAX_PAIR];
static void load_part_trip(double percent){
int i;
for(i=0; i<metadata.n_pair; i++)
pairs[i].trip = percent*trips[i];
}
void search_mult_direction(){
load_part_trip(metadata.stoch_part);
logit_route_direction();
load_part_trip(metadata.determ_part);
search_path_direction();
}
static void init_mult_set(){
printf("init_mult_set()\n");
load_part_trip(metadata.stoch_part);
init_route_set();
load_part_trip(metadata.determ_part);
init_path_set();
}
void init_mult_flow(){
printf("init_mult_flow()\n");
set_flow(0.0);
set_route_flow(0.0);
set_path_flow(0.0);
update_route_cost();
update_path_cost();
search_mult_direction();
set_direction(0.0);
route_to_link_direction();
path_to_link_direction();
update_route_flow(1.0);
update_path_flow(1.0);
update_link_flow(1.0);
}
double master_problem_mixed(double criterion){
double eps = INFINITE, e1, e2, step = 0.0;
printf("master_porblem_mult()\n");
while(eps > criterion){
update_route_cost();
update_path_cost();
search_mult_direction();
step = golden_section(metadata.line_search_eps, 0.0, 1.0, SUE_SO_mixed);
e1 = update_route_flow(step);
e2 = update_path_flow(step);
eps = e1<e2? e2:e1;
update_link_flow(step);
}
return SUE_SO_mixed(step);
}
static bool column_gen_mult(){
bool new_gen = false;
// printf("column_gen_mult()\n");
load_part_trip(metadata.stoch_part);
new_gen = column_gen_route();
load_part_trip(metadata.determ_part);
new_gen = column_gen_path() || new_gen;
return new_gen;
}
void mixed_equilibrium(double criterion){
int i, r, p, l;
bool new_route = true;
double eps = INFINITE, _INT = INFINITE, INT;
for(i=0; i<metadata.n_pair; i++)
trips[i] = pairs[i].trip;
metadata.stoch_part = 1.0 - metadata.determ_part;
printf("\n ...initialize...\n");
// init_link_length();
init_mult_set();
init_mult_flow();
printf("\n ...mixed_equilibrium()...\n");
while(new_route || eps > criterion){
INT = master_problem_mixed(metadata.flow_converg_eps);
new_route = column_gen_mult();
eps = (_INT - INT)/INT;
printf(" eps %e, _INT %e, INT %e\n\n", eps, _INT, INT);
// printf("new route: %d\n\n", new_route);
_INT = INT;
}
for(i=0; i<metadata.n_pair; i++)
pairs[i].trip = trips[i];
update_travel_time();
for(p=0; p<metadata.n_pair; p++){
for(r=0; r<pairs[p].n_path; r++){
pairs[p].paths[r].cost = 0.0;
for(i=0; i<pairs[p].paths[r].leng; i++){
l = pairs[p].paths[r].links[i];
pairs[p].paths[r].cost += links[l].cost;
}
}
}
}
/*
int main(int argc, char *argv[]){
string case_name(argv[1]);
// freopen("debug\\out.txt","w",stdout);
// load_case("TestNet");
// load_case("SiouxFalls");
// load_case("Braess");
load_case("Barcelona");
create_adj_list();
cout<<"start MLT()\n";
objective = SUE_mult_logit;
theta = 1.0;
lambda = 1.0;
determ_part = .0;
stoch_part = 1.0 - determ_part;
mult_logit(obj_converg_eps);
cout<<"end MLT()\n";
save_data("Barcelona");
// save_data("TestNet");
// save_data("Braess");
// save_data("SiouxFalls");
return 0;
}
*/