From 2489ca2ea7f41ce36ea2d8e25757511446b99b0a Mon Sep 17 00:00:00 2001 From: SinusFox <61253950+SinusFox@users.noreply.github.com> Date: Wed, 2 Oct 2024 15:48:43 +0200 Subject: [PATCH] Updating Logs Now the site displays all logs created with customLog(STRING). Logs can be cleared with customLogClear(); --- src/app/scripts.ts | 40 ++++++++++++++++++++++++++++++++-------- 1 file changed, 32 insertions(+), 8 deletions(-) diff --git a/src/app/scripts.ts b/src/app/scripts.ts index 2863aa9..6117819 100644 --- a/src/app/scripts.ts +++ b/src/app/scripts.ts @@ -4,12 +4,26 @@ import * as LPAPI from "../pages/api/optimizeLP.js" import * as GLPKAPI from "../solver/glpk.min.js" -export function test() { - console.log("Dies ist die Testfunktion."); +// custom log so we can append the output dynamically +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 + "
"; // Nachricht anhängen + } +} + +function customLogClear() { + document.getElementById('out').innerHTML =""; } export function calculate_click() { - console.log("Calculating..."); + customLogClear(); + customLog("Calculating...
"); let functions:string|undefined = document.getElementById('funcs').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"; + customLog("Running optimization with input: \"" + wholeText + "\"
"); run(wholeText); @@ -74,21 +89,30 @@ export function calculate_click() { } function run(text:string){ + customLog("Starting problem setup..."); var lp = GLPKAPI.glp_create_prob(); GLPKAPI.glp_read_lp_from_string(lp, null, text); + customLog("Problem created.
"); + customLog("Scaling problem..."); GLPKAPI.glp_scale_prob(lp, GLPKAPI.GLP_SF_AUTO); + customLog("Scaling complete.
"); + customLog("Starting simplex optimization..."); var smcp = new GLPKAPI.SMCP({presolve: GLPKAPI.GLP_ON}); GLPKAPI.glp_simplex(lp, smcp); + customLog("Simplex optimization complete.
"); + customLog("Starting integer optimization..."); var iocp = new GLPKAPI.IOCP({presolve: GLPKAPI.GLP_ON}); GLPKAPI.glp_intopt(lp, iocp); + customLog("Integer optimization complete.
"); - console.log("obj: " + GLPKAPI.glp_mip_obj_val(lp)); - document.getElementById('out').innerHTML = GLPKAPI.glp_mip_obj_val(lp); - for(var i = 1; i <= GLPKAPI.glp_get_num_cols(lp); i++){ - console.log(GLPKAPI.glp_get_col_name(lp, i) + " = " + GLPKAPI.glp_mip_col_val(lp, i)); + // customLog("obj: " + GLPKAPI.glp_mip_obj_val(lp)); + customLog("Final objective value: " + GLPKAPI.glp_mip_obj_val(lp) + "
"); + 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 + 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]); // } // return {name, coefs, vars}; -// } \ No newline at end of file +// }