Adding RegEx input checks and removing license #40
+32
-8
@@ -4,12 +4,26 @@ import * as LPAPI from "../pages/api/optimizeLP.js"
|
|||||||
|
|
||||||
import * as GLPKAPI from "../solver/glpk.min.js"
|
import * as GLPKAPI from "../solver/glpk.min.js"
|
||||||
|
|
||||||
export function test() {
|
// custom log so we can append the output dynamically
|
||||||
console.log("Dies ist die Testfunktion.");
|
function customLog(message: string) {
|
||||||
|
console.log(message); // Nachricht weiterhin in der Konsole ausgeben
|
||||||
|
|
||||||
|
// Hol das Element mit der ID "out"
|
||||||
|
const outputElement = document.getElementById('out');
|
||||||
|
|
||||||
|
// Wenn das Element existiert, füge die Nachricht hinzu
|
||||||
|
if (outputElement) {
|
||||||
|
outputElement.innerHTML += message + "<br>"; // Nachricht anhängen
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function customLogClear() {
|
||||||
|
document.getElementById('out').innerHTML ="";
|
||||||
}
|
}
|
||||||
|
|
||||||
export function calculate_click() {
|
export function calculate_click() {
|
||||||
console.log("Calculating...");
|
customLogClear();
|
||||||
|
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;
|
||||||
@@ -66,6 +80,7 @@ export function calculate_click() {
|
|||||||
|
|
||||||
let wholeText:string = functions + "\nGenerals \n"+variables + "End";
|
let wholeText:string = functions + "\nGenerals \n"+variables + "End";
|
||||||
|
|
||||||
|
customLog("Running optimization with input: \"" + wholeText + "\"<br>");
|
||||||
run(wholeText);
|
run(wholeText);
|
||||||
|
|
||||||
|
|
||||||
@@ -74,21 +89,30 @@ export function calculate_click() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function run(text:string){
|
function run(text:string){
|
||||||
|
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);
|
||||||
|
customLog("Problem created.<br>");
|
||||||
|
|
||||||
|
customLog("Scaling problem...");
|
||||||
GLPKAPI.glp_scale_prob(lp, GLPKAPI.GLP_SF_AUTO);
|
GLPKAPI.glp_scale_prob(lp, GLPKAPI.GLP_SF_AUTO);
|
||||||
|
customLog("Scaling complete.<br>");
|
||||||
|
|
||||||
|
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("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>");
|
||||||
|
|
||||||
console.log("obj: " + GLPKAPI.glp_mip_obj_val(lp));
|
// customLog("obj: " + GLPKAPI.glp_mip_obj_val(lp));
|
||||||
document.getElementById('out').innerHTML = GLPKAPI.glp_mip_obj_val(lp);
|
customLog("<i>Final objective value: " + GLPKAPI.glp_mip_obj_val(lp) + "</i><br>");
|
||||||
for(var i = 1; i <= GLPKAPI.glp_get_num_cols(lp); i++){
|
customLog("Value of each variable:");
|
||||||
console.log(GLPKAPI.glp_get_col_name(lp, i) + " = " + GLPKAPI.glp_mip_col_val(lp, i));
|
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));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -128,4 +152,4 @@ export function export_click() {
|
|||||||
// vars.push(rg.match(/([a-zA-Z][a-zA-Z0-9]*)/g)[0]);
|
// vars.push(rg.match(/([a-zA-Z][a-zA-Z0-9]*)/g)[0]);
|
||||||
// }
|
// }
|
||||||
// return {name, coefs, vars};
|
// return {name, coefs, vars};
|
||||||
// }
|
// }
|
||||||
|
|||||||
Reference in New Issue
Block a user