Adding RegEx input checks and removing license #40
+43
-21
@@ -3,30 +3,53 @@ import * as LP from "../pages/parseLP.ts"
|
|||||||
import * as LPAPI from "../pages/api/optimizeLP.js"
|
import * as LPAPI from "../pages/api/optimizeLP.js"
|
||||||
|
|
||||||
import * as GLPKAPI from "../solver/glpk.min.js"
|
import * as GLPKAPI from "../solver/glpk.min.js"
|
||||||
|
import { start } from "repl";
|
||||||
|
|
||||||
// custom log so we can append the output dynamically
|
// custom log so we can append the output dynamically
|
||||||
function customLog(message: string) {
|
function customLog(message: string) {
|
||||||
console.log(message); // Nachricht weiterhin in der Konsole ausgeben
|
console.log(message); // Continue to print message inside of box
|
||||||
|
|
||||||
// Hol das Element mit der ID "out"
|
// Get Output Box
|
||||||
const outputElement = document.getElementById('out');
|
const outputElement = document.getElementById('out');
|
||||||
|
|
||||||
// Wenn das Element existiert, füge die Nachricht hinzu
|
// Append message if element exists
|
||||||
if (outputElement) {
|
if (outputElement) {
|
||||||
outputElement.innerHTML += message + "<br>"; // Nachricht anhängen
|
outputElement.innerHTML += message + "<br>"; // Append message
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function customLogClear() {
|
function customLogClear() {
|
||||||
document.getElementById('out').innerHTML ="";
|
document.getElementById('out').innerHTML = "";
|
||||||
|
}
|
||||||
|
|
||||||
|
function walltimeStopAndPrint(startpoint: number) {
|
||||||
|
// calculating elapsed time as timestamp
|
||||||
|
var duration = Date.now() - startpoint;
|
||||||
|
|
||||||
|
// Calculate seconds and ms
|
||||||
|
const seconds = Math.floor(duration / 1000);
|
||||||
|
const milliseconds = (duration % 1000) / 1000;
|
||||||
|
|
||||||
|
// formatting
|
||||||
|
const durationFormatted = seconds + (milliseconds >= 0 ? "." : ".") + Math.abs(milliseconds).toFixed(3).slice(2);
|
||||||
|
|
||||||
|
// Printing elapsed time
|
||||||
|
customLog("Elapsed time: " + durationFormatted + " seconds<br>");
|
||||||
|
|
||||||
|
// return durationFormatted;
|
||||||
|
}
|
||||||
|
|
||||||
|
function walltimeStart() {
|
||||||
|
return Date.now();
|
||||||
}
|
}
|
||||||
|
|
||||||
export function calculate_click() {
|
export function calculate_click() {
|
||||||
customLogClear();
|
customLogClear();
|
||||||
|
const timer = walltimeStart();
|
||||||
customLog("Calculating...<br>");
|
customLog("Calculating...<br>");
|
||||||
|
|
||||||
let functions:string|undefined = document.getElementById('funcs').value;
|
let functions: string | undefined = document.getElementById('funcs').value;
|
||||||
let variables:string|undefined = document.getElementById('vars').value;
|
let variables: string | undefined = document.getElementById('vars').value;
|
||||||
|
|
||||||
if (functions == undefined || variables == undefined) return;
|
if (functions == undefined || variables == undefined) return;
|
||||||
// let funcs:string[] = functions.split(/;/);
|
// let funcs:string[] = functions.split(/;/);
|
||||||
@@ -78,17 +101,15 @@ export function calculate_click() {
|
|||||||
|
|
||||||
// console.log(parseFunction(decider));
|
// console.log(parseFunction(decider));
|
||||||
|
|
||||||
let wholeText:string = functions + "\nGenerals \n"+variables + "End";
|
let wholeText: string = functions + "\nGenerals \n" + variables + "End";
|
||||||
|
|
||||||
customLog("Running optimization with input: \"" + wholeText + "\"<br>");
|
customLog("Running optimization with input: \"" + wholeText + "\"<br>");
|
||||||
run(wholeText);
|
run(wholeText);
|
||||||
|
|
||||||
|
walltimeStopAndPrint(timer);
|
||||||
|
}
|
||||||
|
|
||||||
|
function run(text: string) {
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
function run(text:string){
|
|
||||||
customLog("Starting problem setup...");
|
customLog("Starting problem setup...");
|
||||||
var lp = GLPKAPI.glp_create_prob();
|
var lp = GLPKAPI.glp_create_prob();
|
||||||
GLPKAPI.glp_read_lp_from_string(lp, null, text);
|
GLPKAPI.glp_read_lp_from_string(lp, null, text);
|
||||||
@@ -99,31 +120,32 @@ export function calculate_click() {
|
|||||||
customLog("Scaling complete.<br>");
|
customLog("Scaling complete.<br>");
|
||||||
|
|
||||||
customLog("Starting simplex optimization...");
|
customLog("Starting simplex optimization...");
|
||||||
var smcp = new GLPKAPI.SMCP({presolve: GLPKAPI.GLP_ON});
|
var smcp = new GLPKAPI.SMCP({ presolve: GLPKAPI.GLP_ON });
|
||||||
GLPKAPI.glp_simplex(lp, smcp);
|
GLPKAPI.glp_simplex(lp, smcp);
|
||||||
customLog("Simplex optimization complete.<br>");
|
customLog("Simplex optimization complete.<br>");
|
||||||
|
|
||||||
customLog("Starting integer optimization...");
|
customLog("Starting integer optimization...");
|
||||||
var iocp = new GLPKAPI.IOCP({presolve: GLPKAPI.GLP_ON});
|
var iocp = new GLPKAPI.IOCP({ presolve: GLPKAPI.GLP_ON });
|
||||||
GLPKAPI.glp_intopt(lp, iocp);
|
GLPKAPI.glp_intopt(lp, iocp);
|
||||||
customLog("Integer optimization complete.<br>");
|
customLog("Integer optimization complete.<br>");
|
||||||
|
|
||||||
// customLog("obj: " + GLPKAPI.glp_mip_obj_val(lp));
|
// customLog("obj: " + GLPKAPI.glp_mip_obj_val(lp));
|
||||||
customLog("<i>Final objective value: " + GLPKAPI.glp_mip_obj_val(lp) + "</i><br>");
|
customLog("<i>Final objective value: " + GLPKAPI.glp_mip_obj_val(lp) + "</i><br>");
|
||||||
customLog("Value of each variable:");
|
customLog("Value of each variable:");
|
||||||
for(var i = 1; i <= GLPKAPI.glp_get_num_cols(lp) - 1; i++){ // "-1" to remove the "End-variable" from logs
|
for (var i = 1; i <= GLPKAPI.glp_get_num_cols(lp) - 1; i++) { // "-1" to remove the "End-variable" from logs
|
||||||
customLog(GLPKAPI.glp_get_col_name(lp, i) + " = " + GLPKAPI.glp_mip_col_val(lp, i));
|
customLog(GLPKAPI.glp_get_col_name(lp, i) + " = " + GLPKAPI.glp_mip_col_val(lp, i));
|
||||||
}
|
}
|
||||||
|
customLog("");
|
||||||
}
|
}
|
||||||
|
|
||||||
// Irgend ein Interface
|
// Irgend ein Interface
|
||||||
// document.getElementById('out').innerHTML = funcs;
|
// document.getElementById('out').innerHTML = funcs;
|
||||||
|
|
||||||
// output.innerHTML = functions.innerHTML;
|
// output.innerHTML = functions.innerHTML;
|
||||||
|
|
||||||
// createProblemMIP();
|
// createProblemMIP();
|
||||||
|
|
||||||
// LPAPI.default();
|
// LPAPI.default();
|
||||||
|
|
||||||
|
|
||||||
export function import_click() {
|
export function import_click() {
|
||||||
|
|||||||
Reference in New Issue
Block a user