-
Notifications
You must be signed in to change notification settings - Fork 193
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1097 from xor2k/master
Add integrated Webdemo
- Loading branch information
Showing
6 changed files
with
128 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -265,4 +265,7 @@ adlittle.lp | |
qjh.mps | ||
|
||
*.whl | ||
bazel* | ||
bazel* | ||
|
||
# webdemo | ||
build_webdemo |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
<!doctype html> | ||
<!-- compare https://github.com/emscripten-core/emscripten/blob/main/src/shell_minimal.html --> | ||
<html lang="en-us"> | ||
<head> | ||
<meta charset="utf-8"> | ||
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"> | ||
<title>HiGHS</title> | ||
</head> | ||
<body> | ||
<div style="display: grid; grid-template-columns: 1fr 1fr"> | ||
<textarea id="input" style="height: 700px"> | ||
</textarea> | ||
<textarea id="output"></textarea> | ||
<button id="run">Optimize!</button> | ||
</div> | ||
{{{ SCRIPT }}} | ||
<script type='text/javascript'> | ||
main = async () => { | ||
const printInTextarea = function(text) { | ||
if (arguments.length > 1) text = Array.prototype.slice.call(arguments).join(' '); | ||
// These replacements are necessary if you render to raw HTML | ||
//text = text.replace(/&/g, "&"); | ||
//text = text.replace(/</g, "<"); | ||
//text = text.replace(/>/g, ">"); | ||
//text = text.replace('\n', '<br>', 'g'); | ||
// console.log(text); | ||
if (element) { | ||
element.value += text + "\n"; | ||
element.scrollTop = element.scrollHeight; // focus on bottom | ||
} | ||
} | ||
|
||
const highs = await HiGHS({ | ||
print: printInTextarea, | ||
printErr: printInTextarea | ||
}) | ||
|
||
const inputTextarea = document.getElementById('input'); | ||
inputTextarea.value = `Maximize | ||
obj: x1 + 2 x2 + 3 x3 + x4 | ||
Subject To | ||
c1: - x1 + x2 + x3 + 10 x4 <= 20 | ||
c2: x1 - 3 x2 + x3 <= 30 | ||
c3: x2 - 3.5 x4 = 0 | ||
Bounds | ||
0 <= x1 <= 40 | ||
2 <= x4 <= 3 | ||
General | ||
x4 | ||
End`; | ||
|
||
const element = document.getElementById('output'); | ||
const clearOutput = (v) => { | ||
element.value = v || ''; | ||
} | ||
|
||
clearOutput('Click on "Optimize!"') // clear browser cache | ||
|
||
const runButton = document.getElementById('run'); | ||
runButton.addEventListener("click", () => { | ||
clearOutput() | ||
const inputFilename = 'inputFile.lp' | ||
highs.FS.writeFile(inputFilename, inputTextarea.value) | ||
highs.callMain([inputFilename]) | ||
}) | ||
|
||
} | ||
|
||
main() | ||
|
||
</script> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
script_path=$(realpath $(dirname $0)) | ||
build_dir="build_webdemo" | ||
|
||
# interesting for Node.js: -sNODERAWFS=1, allows direct os filesystem access | ||
LDFLAGS=$(echo $(cat << EOF | ||
-sINVOKE_RUN=0 | ||
-sMODULARIZE=1 | ||
-sEXPORTED_RUNTIME_METHODS=['FS','callMain'] | ||
-sEXPORT_NAME='HiGHS' | ||
-sSINGLE_FILE | ||
-sALLOW_MEMORY_GROWTH=1 | ||
--shell-file ${script_path}/app/highs_webdemo_shell.html | ||
EOF | ||
)) | ||
|
||
# compare https://stackoverflow.com/a/6481016 | ||
physical_cores=$(grep ^cpu\\scores /proc/cpuinfo | uniq | awk '{print $4}') | ||
|
||
cd ${script_path} && | ||
rm -rf ${build_dir} && | ||
mkdir ${build_dir} && | ||
cd ${build_dir} && | ||
LDFLAGS=$LDFLAGS emcmake cmake .. \ | ||
-DCMAKE_BUILD_TYPE=Release -DEMSCRIPTEN_HTML=on && | ||
emmake make -j ${physical_cores} |