-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathdemo.html
More file actions
135 lines (121 loc) · 5.3 KB
/
demo.html
File metadata and controls
135 lines (121 loc) · 5.3 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
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Simplex Method Demo</title>
<script src = "LPdefs.js"></script>
<script src = "LPmethods.js"></script>
<script>
lp_reportErrorsTo=lp_reportSolutionTo="solutionout";
var lp_demo_exampleNumber=0;
var lp_demo_accuracy=6;
var lp_demo_mode="decimal";
var lp_demo_verboseLevel=lp_verbosity_none;
var exampleStr = [
"Maximize p = (1/2)x + 3y + z + 4w subject to \nx + y + z + w <= 40\n2x + y - z - w >= 10\nw - y >= 12"
,
"minimize z = 900x1 + 1400x2 + 700x3 + 1000x4 + 1700x5 + 900x6 subject to\nx1 + x2 + x3 <= 10\nx4 + x5 + x6 <= 10\nx1 + x4 >= 6\nx2 + x5 >= 4\nx3 + x6 >= 4\nx4 - x6 <= 0"
,
"Maximize p = (1/2)x + 3y + z + 4w subject to \nx + y + z + w <= 40 \n2x + y - z - w >= 10 \nw - y >= 12 \ninteger w, x, y, z"
,
"Maximize p = x + 2y + 3z subject to \nx + y <= 20.5\ny + z <= 20.5\nx + z <= 30.5\ninteger x, y, z" ,
"Maximize p = x+y\nx+y<=.75\nx+y>=.5\ninteger x,y"]
function showExamples() {
document.getElementById("inputarea").value=exampleStr[lp_demo_exampleNumber%exampleStr.length];
lp_demo_exampleNumber++;
}
function clearAll() {
document.getElementById("inputarea").value="";
document.getElementById("solutionout").innerHTML="An optimal solution (or message) will appear here.";
document.getElementById("outputarea").innerHTML="The tableaus will appear here if desired.";
}
function clearOutput() {
document.getElementById("outputarea").innerHTML="The tableaus will appear here if desired.";
}
function showOutput( str ) {
document.getElementById("outputarea").innerHTML = str;
}
function showSolution( str ) {
document.getElementById("solutionout").innerHTML = str;
}
function adjustAccuracy() {
var inAcc=parseInt(document.getElementById("accuracyDig").value);
if ( (inAcc<=0)||(inAcc>13)||(isNaN(inAcc)) ) {
alert("Must be in integer in the range 0-13")
document.getElementById("accuracyDig").value=6;
}
else lp_demo_accuracy = inAcc;
}
function setMode() {
lp_demo_mode=parseInt(document.querySelector('input[name="modepicker"]:checked').id); // ids are conveniently set to equal the mode
}
function setShowTabl() {
var theId = document.querySelector('input[name="displaytabl"]:checked').id;
switch ( theId ) {
case "yesTabl": lp_demo_verboseLevel = lp_verbosity_tableaus; break;
case "andSolns": lp_demo_verboseLevel = lp_verbosity_solutions; break;
default: lp_demo_verboseLevel = lp_verbosity_none; break;
}
// lp_demo_verboseLevel = (theId=="yesTabl") ? lp_verbosity_tableaus : lp_verbosity_none;
}
</script>
</head>
<body>
<div id = "container" style="width:100%;border:thin black solid;background-color:#dddddd;font-size:12px">
<div id="info1" style="width:100%;text-align:center;margin:5px 0 5px 0">
Type your linear programming problem below. (Press "Examples" to cycle through some problems already set up.) Then press "Solve".
</div>
<center>
<div id="input">
<textarea rows="15" cols="15" id="inputarea" style="width:95%"></textarea>
</div>
<div id="info2" style="width:100%;text-align:center;margin:5px 0 5px 0">
Solution:
</div>
<div id="solutionout" style="text-align:left;background-color:white;width:95%;font-family:monospace;border:thin solid;padding:10px">
An optimal solution (or message) will appear here.
</div>
<div id="buttonsdiv" style="width:100%;text-align:center;margin:5px 0 5px 0">
<input type="button" value="Solve"
onClick="clearOutput();
adjustAccuracy();setMode();setShowTabl();
var Q = new lpProblem( document.getElementById('inputarea').value );
lp_verboseLevel=lp_demo_verboseLevel;
Q.mode=lp_demo_mode;
Q.sigDigits=lp_demo_accuracy;
try{Q.solve()}
finally{showOutput( lp_trace_string );showSolution( Q.solutionToString() );}
">
   
<input type="button" value="Examples" onClick="showExamples();">
   
<input type="button" value="Erase everything" onClick="clearAll();">
<br> <br>
<div style="display: inline-block; vertical-align:middle; text-align:left">
<input type="radio" name="displaytabl" id="noTabl"> Hide tableaus.
<br>
<input type="radio" checked="true" name="displaytabl" id="yesTabl"> Show tableaus (slower).
<br>
<input type="radio" name="displaytabl" id="andSolns"> Show tableaus and intermediate solutions.
</div>
   
Tableau mode: <div style="display: inline-block; vertical-align:middle; text-align:left">
<input type="radio" checked="true" name="modepicker" id="3" value="decimal"> decimal
<br>
<input type="radio" name="modepicker" id="2" value="fraction"> fraction
<br>
<input type="radio" name="modepicker" id="1" value="integer"> integer
</div>
   
Rounding: <input type="text" id="accuracyDig" size="1" value="6"> significant digits
   
</div>
<div id="outputarea" style="width: 95%; overflow-x: scroll; background-color:white; font-family:monospace; border: thin solid; padding: 10px; text-align:left">
The tableaus will appear here if desired.
</div>
<div id="spacer" style="height:20px"></div>
</center>
</div>
</body>
</html>