forked from vihaanthora/milp-python
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
59 lines (50 loc) · 1.2 KB
/
main.py
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
import argparse
from operator import itemgetter
from data import (
LP_form,
unflatten,
import_constraints,
export_results,
processZ,
calc_obj,
)
from wrapper import solve
parser = argparse.ArgumentParser(prog="MILP Python", description="Solve MILPs")
parser.add_argument(
"-m",
metavar="method",
dest="method",
choices=(1, 2),
type=int,
default=1,
help="1. Matrix Simplex Method\n2. Tableau Simplex Method",
)
parser.add_argument(
"-i",
metavar="input",
dest="input",
type=str,
default="data/inp1.json",
help="Input file path",
)
parser.add_argument(
"-o",
metavar="output",
dest="output",
type=str,
default="data/out.json",
help="Output file path",
)
args = parser.parse_args()
INFILE_PATH = args.input
OUTFILE_PATH = args.output
METHOD = args.method
consts = import_constraints(INFILE_PATH)
A, b, c = LP_form(**consts)
solution, itermap, time = solve(A, b, c, method=METHOD)
n, m, t, D = itemgetter("n", "m", "t", "D")(consts)
solution = processZ(solution, D, n, m, t)
X, Y, Z = unflatten(solution, n, m, t)
objf = calc_obj(solution, c)
iter = max(itermap.keys())
export_results(OUTFILE_PATH, X, Y, Z, iter, objf, 1)