-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.cpp
147 lines (119 loc) · 4.34 KB
/
main.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
#include "main.h"
using namespace std;
int main(int argc, char** argv)
{
// Some variables that will be filled with values given through the commandline
string input; // Inputfilename
string input_carry; // Inputfilename for carry matrix
string input_basis; // Inputfilename for basis
bool display_problem = false; // Whether to display problem again
bool display_objective = false; // Whether to display objective
bool display_variables = false; // Whether to display variables
bool optimize = false; // Whether to optimize
int start_phase = 1;
// Handle commandline arguments using the nice TCLAP library
// @see http://tclap.sourceforge.net/
//
// Wrap everything in a try block. Do this every time,
// because exceptions will be thrown for problems.
try {
// ============ Define available arguments ============
// Define the command line object, and insert a message
// that describes the program. The "Command description message"
// is printed last in the help text. The second argument is the
// delimiter (usually space) and the last one is the version number.
// The CmdLine object parses the argv array based on the Arg objects
// that it contains.
TCLAP::CmdLine cmd("TTVPlex - Revised Simplex Algorithm", ' ', "0.1");
// Define a value argument and add it to the command line.
// A value arg defines a flag and a type of value that it expects,
// such as "-n Bishop".
TCLAP::ValueArg<int> verbosityArg("v","verbosity","Verbosity of output (0 to 3)", false, 1, "int");
// Add the argument nameArg to the CmdLine object. The CmdLine object
// uses this Arg to parse the command line.
cmd.add( verbosityArg );
TCLAP::ValueArg<string> inputArg("i","input","Input LP file", true, "", "string");
cmd.add( inputArg );
TCLAP::ValueArg<string> input_carryArg("c","carry","Input file with a carry matrix to start from", false, "", "string");
cmd.add( input_carryArg );
TCLAP::ValueArg<string> input_basisArg("b","basis","Input file with a basis to start from", false, "", "string");
cmd.add( input_basisArg );
TCLAP::ValueArg<int> start_phaseArg("s","phase","Phase to start in. 1 or 2", false, 1, "int");
cmd.add( start_phaseArg );
TCLAP::ValueArg<int> maxitArg("m","maxit","Maximum number of iterations", false, 0, "int");
cmd.add( maxitArg );
TCLAP::SwitchArg display_problemArg("p","problem","Display problem?", false);
cmd.add( display_problemArg );
TCLAP::SwitchArg display_objectiveArg("o","objective","Display objective?", false);
cmd.add( display_objectiveArg );
TCLAP::SwitchArg display_variablesArg("w","variables","Display variables?", false);
cmd.add( display_variablesArg );
TCLAP::SwitchArg optimizeArg("x","optimize","Execute optimization?", false);
cmd.add( optimizeArg );
// Parse the argv array.
cmd.parse( argc, argv );
// ============ Postprocess some of the arguments ============
// Get the value parsed by each arg.
int verbosity = verbosityArg.getValue();
lout << "Verbosity of output: " << verbosity << "\n";
if (verbosity < 3) {
ldbg.level = 0;
}
if (verbosity < 2) {
linf.level = 0;
}
if (verbosity < 1) {
lout.level = 0;
lerr.level = 0;
}
input = inputArg.getValue();
input_carry = input_carryArg.getValue();
input_basis = input_basisArg.getValue();
max_iterations = maxitArg.getValue();
display_problem = display_problemArg.getValue();
display_objective = display_objectiveArg.getValue();
display_variables = display_variablesArg.getValue();
optimize = optimizeArg.getValue();
start_phase = start_phaseArg.getValue();
}
catch (TCLAP::ArgException &e) // catch any exceptions
{
cerr << "error: " << e.error() << " for arg " << e.argId() << endl;
exit(EXIT_FAILURE);
}
LPParser lp(input);
lp.read();
if (display_problem)
{
lout << "===================================================\n";
lout << "LP read from file: '" << input << "'\n";
lp.dump(lout);
lout << "\n";
}
lp.standardize();
if (display_problem)
{
lout << "===================================================\n";
lout << "LP now in standard form:\n";
lp.dump(lout);
lout << "\n";
}
Simplex smp(lp);
smp.init(input_carry, input_basis, start_phase);
if (optimize)
{
smp.optimize();
}
if (display_objective)
{
lout << "\n";
smp.objective();
}
if (display_variables)
{
lout << "\n";
smp.variables();
}
exit(EXIT_SUCCESS);
return 0;
}