Adding MPS Export #49

Merged
SinusFox merged 61 commits from adding-unit-tests-and-language-switching into main 2024-10-11 14:08:24 +00:00
3 changed files with 52 additions and 29 deletions
Showing only changes of commit 62c3f7c55c - Show all commits
+10
View File
@@ -172,3 +172,13 @@ body {
.dropdown-custom:hover { .dropdown-custom:hover {
background-color: #444; background-color: #444;
} }
.dropdown-custom-maxmin {
width: 150px;
background-color: black;
color: white;
border: none;
padding: 10px;
font-size: 16px;
cursor: pointer;
}
+32 -17
View File
@@ -2,11 +2,13 @@
import React, { useState } from 'react'; import React, { useState } from 'react';
import { Box, Button, Output } from "./modules"; import { Box, Button, Output } from "./modules";
import { calculate_clickMaximize, calculate_clickMinimize, downloadLP, import_click } from "./scripts" import { calculate_click, downloadLP, import_click } from "./scripts";
import text from "./lang" import text from "./lang";
export default function Home() { export default function Home() {
const [language, setLanguage] = useState('eng'); const [language, setLanguage] = useState('eng');
const [maxminOption, setMaxminOption] = useState('maximize'); // Zustand für den MaxMin-Switch
const tr_hTitle = text(language, 'header_title'); const tr_hTitle = text(language, 'header_title');
const tr_hSubtitle = text(language, 'header_subtitle'); const tr_hSubtitle = text(language, 'header_subtitle');
const tr_boxObjTitle = text(language, 'boxObjTitle'); const tr_boxObjTitle = text(language, 'boxObjTitle');
@@ -21,21 +23,27 @@ export default function Home() {
const tr_boxExportLP = text(language, "boxExportLP"); const tr_boxExportLP = text(language, "boxExportLP");
const tr_calc_max = text(language, "maximize"); const tr_calc_max = text(language, "maximize");
const tr_calc_min = text(language, "minimize"); const tr_calc_min = text(language, "minimize");
const tr_calcButton = text(language, "buttonCalc");
const handleLanguageChange = (event: React.ChangeEvent<HTMLSelectElement>) => { const handleLanguageChange = (event: React.ChangeEvent<HTMLSelectElement>) => {
setLanguage(event.target.value); setLanguage(event.target.value);
}; };
const handleMaxMinChange = (event: React.ChangeEvent<HTMLSelectElement>) => {
setMaxminOption(event.target.value); // Update den Zustand basierend auf dem Wert des Selects
};
return ( return (
<> <>
<header className="header"> <header className="header">
<div className="title"> <div className="title">
<main className="header_box"> <main className="header_box">
{tr_hTitle} {tr_hTitle}
<br></br> <br />
<span className="header_copyright"> <span className="header_copyright">
<i>{tr_hSubtitle}</i> <i>{tr_hSubtitle}</i>
</span><br></br> </span>
<br />
<select id="language_current" value={language} onChange={handleLanguageChange} className="dropdown-custom"> <select id="language_current" value={language} onChange={handleLanguageChange} className="dropdown-custom">
<option value="ger">Deutsch</option> <option value="ger">Deutsch</option>
<option value="eng">English</option> <option value="eng">English</option>
@@ -46,35 +54,42 @@ export default function Home() {
<Box <Box
title={tr_boxObjTitle} title={tr_boxObjTitle}
placeholder={tr_boxObjDesc} placeholder={tr_boxObjDesc}
id="objective" /> id="objective"
/>
<Box <Box
title={tr_boxSubjTitle} title={tr_boxSubjTitle}
placeholder={tr_boxSubjDesc} placeholder={tr_boxSubjDesc}
id="subject" /> id="subject"
/>
<Box <Box
title={tr_boxBoundsTitle} title={tr_boxBoundsTitle}
placeholder={tr_boxBoundsDesc} placeholder={tr_boxBoundsDesc}
id="bounds" /> id="bounds"
/>
<Box <Box
title={tr_boxVarsTitle} title={tr_boxVarsTitle}
placeholder={tr_boxVarsDesc} placeholder={tr_boxVarsDesc}
id="vars" /> id="vars"
/>
<select id="maxminswitch" value={maxminOption} onChange={handleMaxMinChange} className="dropdown-custom-maxmin">
<option value="maximize">{tr_calc_max}</option>
<option value="minimize">{tr_calc_min}</option>
</select>
<Button <Button
title={tr_calc_max} title={tr_calcButton}
className={"button_green"} className={"button_green"}
onClickFunc={calculate_clickMaximize} /> onClickFunc={calculate_click}
<Button />
title={tr_calc_min}
className={"button_green"}
onClickFunc={calculate_clickMinimize} />
<Button <Button
title={tr_boxExportLP} title={tr_boxExportLP}
className={"button"} className={"button"}
onClickFunc={downloadLP} /> onClickFunc={downloadLP}
<br></br> />
<br />
<Output <Output
id="out" id="out"
text={tr_boxOut} /> text={tr_boxOut}
/>
</> </>
); );
} }
+10 -12
View File
@@ -128,7 +128,7 @@ function isInputFilled(obj: string | undefined, subj: string | undefined, bounds
return true; return true;
} }
function calculate_click(maximize: boolean) { export function calculate_click() {
customLogClear(); customLogClear();
const timer = walltimeStart(); const timer = walltimeStart();
customLog("calculating"); customLog("calculating");
@@ -215,8 +215,9 @@ function calculate_click(maximize: boolean) {
if (!isInputValidRegex(objective, subject, bounds, variables)) return; if (!isInputValidRegex(objective, subject, bounds, variables)) return;
// fetch operator // fetch operator
const maxmin = (document.getElementById('maxminswitch') as HTMLSelectElement)?.value;
let operator = "Minimize"; let operator = "Minimize";
if (maximize) operator = "Maximize"; if (maxmin == "maximize") operator = "Maximize";
let wholeText: string = operator + "\n obj: " + objective let wholeText: string = operator + "\n obj: " + objective
+ "\nSubject To \n" + subject + "\nSubject To \n" + subject
@@ -284,11 +285,17 @@ function downloadLPFormatting(objective: any, subject: any, bounds: any) {
const formattedSubject = typeof subject === 'string' ? subject : ''; const formattedSubject = typeof subject === 'string' ? subject : '';
const formattedBounds = typeof bounds === 'string' ? bounds : ''; const formattedBounds = typeof bounds === 'string' ? bounds : '';
// fetch operator
const maxmin = (document.getElementById('maxminswitch') as HTMLSelectElement)?.value;
let operator = "Minimize";
if (maxmin == "maximize") operator = "Maximize";
// Header mit Problemname // Header mit Problemname
const header = "\\ Your problem\n"; const header = "\\ Your problem\n";
// format objective // format objective
const objectiveFunction = `Maximize\n obj: ${formattedObjective}\n`;
const objectiveFunction = operator + `\n obj: ${formattedObjective}\n`;
// turn each subject into a single line // turn each subject into a single line
const constraints = `Subject To\n${formattedSubject.split("\n").filter(line => line.trim() !== "").map(line => ` ${line}`).join("\n")}\n`; const constraints = `Subject To\n${formattedSubject.split("\n").filter(line => line.trim() !== "").map(line => ` ${line}`).join("\n")}\n`;
@@ -302,15 +309,6 @@ function downloadLPFormatting(objective: any, subject: any, bounds: any) {
return lpFormat; return lpFormat;
} }
export function calculate_clickMaximize() {
calculate_click(true);
}
export function calculate_clickMinimize() {
calculate_click(false);
}
function downloadProblemDownload(content: string) { function downloadProblemDownload(content: string) {
customLog("downloadPrepFile"); customLog("downloadPrepFile");
customLog(""); customLog("");