forked from Tian-Xie/NLS
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathNestedLogitTester.cpp
More file actions
108 lines (85 loc) · 3.23 KB
/
NestedLogitTester.cpp
File metadata and controls
108 lines (85 loc) · 3.23 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
#include "NestedLogitTester.h"
#include <time.h>
#include <math.h>
#include <vector>
using std::vector;
void TestDisjoint(FILE* out, int m, int n, vector <double> _ratio, int useCPLEX)
{
NestedLogitModel Model;
int seed = time(0);
Model.RandomCase(m, n, seed);
clock_t startTime, endTime;
double sec, ans;
if (out) fprintf(out, "------ Disjoint: m = %d, n = %d, seed = %d, ------\n", m, n, seed);
fprintf(stderr, "------ Disjoint: m = %d, n = %d, seed = %d ------\n", m, n, seed);
startTime = clock();
Model.GenerateAllCandidateSet();
endTime = clock();
sec = (double) (endTime - startTime) / CLOCKS_PER_SEC;
if (out) fprintf(out, "GenerateAllCandidateSet: %.4lf\n", sec);
fprintf(stderr, "GenerateAllCandidateSet: %.4lf\n", sec);
NestedLogitSolver Solver(Model);
for (auto ratio: _ratio)
{
if (out) fprintf(out, "------ ratio: %.2lf ------\n", ratio);
fprintf(stderr, "------ ratio: %.2lf ------\n", ratio);
vector <int> C(m, (int) ceil(n * ratio));
startTime = clock();
ans = Solver.SolveDisjoint(C);
endTime = clock();
sec = (double) (endTime - startTime) / CLOCKS_PER_SEC;
if (out) fprintf(out, "%.10lf \t SolveDisjoint: %.4lf\n", ans, sec);
fprintf(stderr, "%.10lf \t SolveDisjoint: %.4lf\n", ans, sec);
if (useCPLEX)
{
startTime = clock();
ans = Solver.SolveDisjointCPLEX(C);
endTime = clock();
sec = (double) (endTime - startTime) / CLOCKS_PER_SEC;
if (out) fprintf(out, "%.10lf \t SolveDisjointCPLEX: %.4lf\n", ans, sec);
fprintf(stderr, "%.10lf \t SolveDisjointCPLEX: %.4lf\n", ans, sec);
}
}
if (out) fprintf(out, "------ Finish ------\n");
fprintf(stderr, "------ Finish ------\n");
}
void TestJoint(FILE* out, int m, int n, vector <double> _ratio, int useCPLEX)
{
NestedLogitModel Model;
int seed = time(0);
Model.RandomCase(m, n, seed);
clock_t startTime, endTime;
double sec, ans;
if (out) fprintf(out, "------ Joint: m = %d, n = %d, seed = %d ------\n", m, n, seed);
fprintf(stderr, "------ Joint: m = %d, n = %d, seed = %d ------\n", m, n, seed);
startTime = clock();
Model.GenerateAllCandidateSet();
endTime = clock();
sec = (double) (endTime - startTime) / CLOCKS_PER_SEC;
if (out) fprintf(out, "GenerateAllCandidateSet: %.4lf\n", sec);
fprintf(stderr, "GenerateAllCandidateSet: %.4lf\n", sec);
NestedLogitSolver Solver(Model);
for (auto ratio: _ratio)
{
if (out) fprintf(out, "------ ratio: %.2lf ------\n", ratio);
fprintf(stderr, "------ ratio: %.2lf ------\n", ratio);
int C = (int) ceil(m * n * ratio);
startTime = clock();
ans = Solver.SolveJoint(C);
endTime = clock();
sec = (double) (endTime - startTime) / CLOCKS_PER_SEC;
if (out) fprintf(out, "%.10lf \t SolveJoint: %.4lf\n", ans, sec);
fprintf(stderr, "%.10lf \t SolveJoint: %.4lf\n", ans, sec);
if (useCPLEX)
{
startTime = clock();
ans = Solver.SolveJointCPLEX(C);
endTime = clock();
sec = (double) (endTime - startTime) / CLOCKS_PER_SEC;
if (out) fprintf(out, "%.10lf \t SolveJointCPLEX: %.4lf\n", ans, sec);
fprintf(stderr, "%.10lf \t SolveJointCPLEX: %.4lf\n", ans, sec);
}
}
if (out) fprintf(out, "------ Finish ------\n");
fprintf(stderr, "------ Finish ------\n");
}