From 5c0ff6e7e01730be2b790e4ade946d342b9291ab Mon Sep 17 00:00:00 2001 From: zaibod Date: Sun, 9 Feb 2025 20:23:28 +0100 Subject: [PATCH 01/14] chore: added bound representations as interfaces, updated problemdto --- src/api/data-model/BoundComparisonDto.ts | 8 ++++++++ src/api/data-model/BoundDto.ts | 7 +++++++ src/api/data-model/BoundType.ts | 4 ++++ src/api/data-model/ProblemDto.ts | 3 +++ 4 files changed, 22 insertions(+) create mode 100644 src/api/data-model/BoundComparisonDto.ts create mode 100644 src/api/data-model/BoundDto.ts create mode 100644 src/api/data-model/BoundType.ts diff --git a/src/api/data-model/BoundComparisonDto.ts b/src/api/data-model/BoundComparisonDto.ts new file mode 100644 index 0000000..3a2f3ef --- /dev/null +++ b/src/api/data-model/BoundComparisonDto.ts @@ -0,0 +1,8 @@ +import { BoundDto } from "./BoundDto"; +import { SolutionObject } from "./SolutionObject"; + +export interface BoundComparisonDto { + comparison: number; + bound: BoundDto; + solution: SolutionObject; +} diff --git a/src/api/data-model/BoundDto.ts b/src/api/data-model/BoundDto.ts new file mode 100644 index 0000000..63be861 --- /dev/null +++ b/src/api/data-model/BoundDto.ts @@ -0,0 +1,7 @@ +import { BoundType } from "./BoundType"; + +export interface BoundDto { + bound: number; + boundType: BoundType; + executionTime: number; +} diff --git a/src/api/data-model/BoundType.ts b/src/api/data-model/BoundType.ts new file mode 100644 index 0000000..fc37e0c --- /dev/null +++ b/src/api/data-model/BoundType.ts @@ -0,0 +1,4 @@ +export enum BoundType { + UPPER = "UPPER", + LOWER = "LOWER", +} diff --git a/src/api/data-model/ProblemDto.ts b/src/api/data-model/ProblemDto.ts index 5af02f8..8defb6d 100644 --- a/src/api/data-model/ProblemDto.ts +++ b/src/api/data-model/ProblemDto.ts @@ -1,3 +1,4 @@ +import { BoundDto } from "./BoundDto"; import { ProblemState } from "./ProblemState"; import { getInvalidSolutionObject, SolutionObject } from "./SolutionObject"; import { SolverSetting } from "./SolverSettings"; @@ -8,6 +9,7 @@ export interface ProblemDto { typeId: string; input: T; solution: SolutionObject; + bound: BoundDto; state: ProblemState; solverId?: string; solverSettings: SolverSetting[]; @@ -21,6 +23,7 @@ export function getInvalidProblemDto(): ProblemDto { id: "", input: {} as T, solution: getInvalidSolutionObject(), + bound: {} as BoundDto, solverId: "", solverSettings: [], state: ProblemState.READY_TO_SOLVE, From 44b69d630d117b2f25423a0ad7d902177aa1468c Mon Sep 17 00:00:00 2001 From: zaibod Date: Sun, 9 Feb 2025 20:24:37 +0100 Subject: [PATCH 02/14] chore: added bound api endpoints to api functions --- src/api/ToolboxAPI.ts | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/src/api/ToolboxAPI.ts b/src/api/ToolboxAPI.ts index 741e6a6..7460039 100644 --- a/src/api/ToolboxAPI.ts +++ b/src/api/ToolboxAPI.ts @@ -151,3 +151,30 @@ export async function fetchExampleProblems(problemTypeId: string) { }, }).then((response) => response.json()); } + +export async function fetchProblemBounds( + problemTypeId: string, + problemId: string +) { + return fetch(`${baseUrl()}/problems/${problemTypeId}/${problemId}/bound`, { + method: "GET", + headers: { + "Content-Type": "application/json", + }, + }).then((response) => response.json()); +} + +export async function fetchProblemBoundComparison( + problemTypeId: string, + problemId: string +) { + return fetch( + `${baseUrl()}/problems/${problemTypeId}/${problemId}/bound/comparison`, + { + method: "GET", + headers: { + "Content-Type": "application/json", + }, + } + ).then((response) => response.json()); +} From f22f7a1fd7e396708379aabae92ff1ef84c8836f Mon Sep 17 00:00:00 2001 From: zaibod Date: Sun, 9 Feb 2025 20:25:27 +0100 Subject: [PATCH 03/14] feat: very preliminary bound display --- src/components/solvers/SolutionView.tsx | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/components/solvers/SolutionView.tsx b/src/components/solvers/SolutionView.tsx index 0a64a71..9e38f13 100644 --- a/src/components/solvers/SolutionView.tsx +++ b/src/components/solvers/SolutionView.tsx @@ -44,6 +44,20 @@ const OutputSection = (props: { title: string; content: any[] }) => ( ); +const BoundComparisonSection = () => ( + +

+ + + Bound Comparison + + + +

+ +
+); + export const SolutionView = (props: SolutionViewProps) => ( ( title="Debugging Info" content={[props.solution.debugData]} /> + {/**/} {/**/} ); From f986a941e7ae1dc5012740c86371a65808f95bb6 Mon Sep 17 00:00:00 2001 From: zaibod Date: Tue, 15 Apr 2025 03:21:10 +0200 Subject: [PATCH 04/14] fix: corrected bound comparison endpoint --- src/api/ToolboxAPI.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/api/ToolboxAPI.ts b/src/api/ToolboxAPI.ts index e248f1d..630e4ed 100644 --- a/src/api/ToolboxAPI.ts +++ b/src/api/ToolboxAPI.ts @@ -169,7 +169,7 @@ export async function fetchProblemBoundComparison( problemId: string ) { return fetch( - `${baseUrl()}/problems/${problemTypeId}/${problemId}/bound/comparison`, + `${baseUrl()}/problems/${problemTypeId}/${problemId}/bound/compare`, { method: "GET", headers: { From 76d2bec02d7182745e24b1cfdd5b1c99e414a87e Mon Sep 17 00:00:00 2001 From: zaibod Date: Tue, 15 Apr 2025 03:21:24 +0200 Subject: [PATCH 05/14] feat: added error handling --- src/api/ToolboxAPI.ts | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/src/api/ToolboxAPI.ts b/src/api/ToolboxAPI.ts index 630e4ed..3218869 100644 --- a/src/api/ToolboxAPI.ts +++ b/src/api/ToolboxAPI.ts @@ -161,7 +161,12 @@ export async function fetchProblemBounds( headers: { "Content-Type": "application/json", }, - }).then((response) => response.json()); + }).then( + (response) => response.json(), + (reason) => { + return { error: reason }; + } + ); } export async function fetchProblemBoundComparison( @@ -176,5 +181,10 @@ export async function fetchProblemBoundComparison( "Content-Type": "application/json", }, } - ).then((response) => response.json()); + ).then( + (response) => response.json(), + (reason) => { + return { error: reason }; + } + ); } From bf70a9b64374237d9e5f21190c3fa9f605559a7e Mon Sep 17 00:00:00 2001 From: zaibod Date: Tue, 15 Apr 2025 03:21:52 +0200 Subject: [PATCH 06/14] feat: added variable-dependent display component --- .../solvers/VariableDependentDisplay.tsx | 52 +++++++++++++++++++ 1 file changed, 52 insertions(+) create mode 100644 src/components/solvers/VariableDependentDisplay.tsx diff --git a/src/components/solvers/VariableDependentDisplay.tsx b/src/components/solvers/VariableDependentDisplay.tsx new file mode 100644 index 0000000..82d7008 --- /dev/null +++ b/src/components/solvers/VariableDependentDisplay.tsx @@ -0,0 +1,52 @@ +import { Button, Text } from "@chakra-ui/react"; +import { BoundComparisonDto } from "../../api/data-model/BoundComparisonDto"; + +export interface VariableDependentDisplayProps { + buttonTitle: string; + variable: any | null | undefined; + getter: () => any; +} + +export const VariableDependentDisplay = ( + props: VariableDependentDisplayProps +) => { + return ( + <> + {props.variable ? ( + JSON.stringify(props.variable) + ) : ( + + )} + + ); +}; + +export interface BoundDisplayProps { + buttonTitle: string; + variable: BoundComparisonDto; + getter: () => any; +} + +function toTitleCase(input: string) { + return input.charAt(0).toUpperCase() + input.slice(1).toLowerCase(); +} + +export const BoundDisplay = (props: BoundDisplayProps) => { + return ( + <> + {props.variable?.bound ? ( + + {" "} + {toTitleCase(props.variable.bound.boundType)} bound:{" "} + {props.variable.bound.value} + + ) : ( + + )} + + ); +}; From 16ce7ea2547f0dfa8b34b905bb5d18b3defb787f Mon Sep 17 00:00:00 2001 From: zaibod Date: Tue, 15 Apr 2025 03:26:26 +0200 Subject: [PATCH 07/14] fix: renamed bound value to fit backend --- src/api/data-model/BoundDto.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/api/data-model/BoundDto.ts b/src/api/data-model/BoundDto.ts index 63be861..08fa06e 100644 --- a/src/api/data-model/BoundDto.ts +++ b/src/api/data-model/BoundDto.ts @@ -1,7 +1,7 @@ import { BoundType } from "./BoundType"; export interface BoundDto { - bound: number; + value: number; boundType: BoundType; executionTime: number; } From 73718672bec70f327247b09aea75ce75ed4df5d5 Mon Sep 17 00:00:00 2001 From: zaibod Date: Tue, 15 Apr 2025 03:27:05 +0200 Subject: [PATCH 08/14] refactor: changed to correct type --- src/api/data-model/BoundComparisonDto.ts | 12 ++++++++++-- src/api/data-model/ProblemDto.ts | 2 +- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/src/api/data-model/BoundComparisonDto.ts b/src/api/data-model/BoundComparisonDto.ts index 3a2f3ef..f310812 100644 --- a/src/api/data-model/BoundComparisonDto.ts +++ b/src/api/data-model/BoundComparisonDto.ts @@ -1,8 +1,16 @@ -import { BoundDto } from "./BoundDto"; -import { SolutionObject } from "./SolutionObject"; +import { BoundDto, getInvalidBoundDto } from "./BoundDto"; +import { getInvalidSolutionObject, SolutionObject } from "./SolutionObject"; export interface BoundComparisonDto { comparison: number; bound: BoundDto; solution: SolutionObject; } + +export function getInvalidBoundComparisonDto(): BoundComparisonDto { + return { + bound: getInvalidBoundDto(), + comparison: 0, + solution: getInvalidSolutionObject(), + }; +} diff --git a/src/api/data-model/ProblemDto.ts b/src/api/data-model/ProblemDto.ts index 8defb6d..f70521f 100644 --- a/src/api/data-model/ProblemDto.ts +++ b/src/api/data-model/ProblemDto.ts @@ -9,7 +9,7 @@ export interface ProblemDto { typeId: string; input: T; solution: SolutionObject; - bound: BoundDto; + bound: BoundComparisonDto; state: ProblemState; solverId?: string; solverSettings: SolverSetting[]; From 2fba98f3706f4b99a75e1c70e1226e719597d5da Mon Sep 17 00:00:00 2001 From: zaibod Date: Tue, 15 Apr 2025 03:27:37 +0200 Subject: [PATCH 09/14] feat: added invalid object generators --- src/api/data-model/BoundDto.ts | 8 ++++++++ src/api/data-model/ProblemDto.ts | 7 +++++-- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/src/api/data-model/BoundDto.ts b/src/api/data-model/BoundDto.ts index 08fa06e..bbb991f 100644 --- a/src/api/data-model/BoundDto.ts +++ b/src/api/data-model/BoundDto.ts @@ -5,3 +5,11 @@ export interface BoundDto { boundType: BoundType; executionTime: number; } + +export function getInvalidBoundDto(): BoundDto { + return { + value: NaN, + boundType: BoundType.UPPER, + executionTime: -1, + }; +} diff --git a/src/api/data-model/ProblemDto.ts b/src/api/data-model/ProblemDto.ts index f70521f..db32f80 100644 --- a/src/api/data-model/ProblemDto.ts +++ b/src/api/data-model/ProblemDto.ts @@ -1,4 +1,7 @@ -import { BoundDto } from "./BoundDto"; +import { + BoundComparisonDto, + getInvalidBoundComparisonDto, +} from "./BoundComparisonDto"; import { ProblemState } from "./ProblemState"; import { getInvalidSolutionObject, SolutionObject } from "./SolutionObject"; import { SolverSetting } from "./SolverSettings"; @@ -23,7 +26,7 @@ export function getInvalidProblemDto(): ProblemDto { id: "", input: {} as T, solution: getInvalidSolutionObject(), - bound: {} as BoundDto, + bound: getInvalidBoundComparisonDto(), solverId: "", solverSettings: [], state: ProblemState.READY_TO_SOLVE, From 659cc2caafd1f3623ab80118f517bc618a35e68d Mon Sep 17 00:00:00 2001 From: zaibod Date: Tue, 15 Apr 2025 03:28:59 +0200 Subject: [PATCH 10/14] refactor: changed solutionview argument now accepts whole problemdto instead of just the solution to prepare for bounds --- src/components/solvers/Graph/ProblemDetails.tsx | 2 +- src/components/solvers/Graph/ProblemGraphView.tsx | 2 +- src/components/solvers/SolutionView.tsx | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/components/solvers/Graph/ProblemDetails.tsx b/src/components/solvers/Graph/ProblemDetails.tsx index 0a206c7..90fa004 100644 --- a/src/components/solvers/Graph/ProblemDetails.tsx +++ b/src/components/solvers/Graph/ProblemDetails.tsx @@ -95,7 +95,7 @@ export const ProblemDetails = (props: { problemDto: ProblemDto }) => { {props.problemDto.solution !== null && ( Solution: - + )} diff --git a/src/components/solvers/Graph/ProblemGraphView.tsx b/src/components/solvers/Graph/ProblemGraphView.tsx index 18d354b..ff96f49 100644 --- a/src/components/solvers/Graph/ProblemGraphView.tsx +++ b/src/components/solvers/Graph/ProblemGraphView.tsx @@ -636,7 +636,7 @@ export const ProblemGraphView = (props: ProblemGraphViewProps) => { nodes[0].data.problemDtos?.length > 0 && nodes[0].data.problemDtos[0].state === ProblemState.SOLVED && ( - + )} diff --git a/src/components/solvers/SolutionView.tsx b/src/components/solvers/SolutionView.tsx index 9e38f13..9765cee 100644 --- a/src/components/solvers/SolutionView.tsx +++ b/src/components/solvers/SolutionView.tsx @@ -10,7 +10,7 @@ import { import { SolutionObject } from "../../api/data-model/SolutionObject"; export interface SolutionViewProps { - solution: SolutionObject; + problem: ProblemDto; } const OutputSection = (props: { title: string; content: any[] }) => ( From a23065e6f033445519fcf85a0110c8ca25337e7c Mon Sep 17 00:00:00 2001 From: zaibod Date: Tue, 15 Apr 2025 03:29:24 +0200 Subject: [PATCH 11/14] feat: added bound and boundComparison displays --- .../solvers/Graph/ProblemDetails.tsx | 18 +++ src/components/solvers/SolutionView.tsx | 133 ++++++++++++++---- 2 files changed, 123 insertions(+), 28 deletions(-) diff --git a/src/components/solvers/Graph/ProblemDetails.tsx b/src/components/solvers/Graph/ProblemDetails.tsx index 90fa004..a4caf2b 100644 --- a/src/components/solvers/Graph/ProblemDetails.tsx +++ b/src/components/solvers/Graph/ProblemDetails.tsx @@ -12,8 +12,10 @@ import { import { ReactNode } from "react"; import { ProblemDto } from "../../../api/data-model/ProblemDto"; import { ProblemState } from "../../../api/data-model/ProblemState"; +import { fetchProblemBounds } from "../../../api/ToolboxAPI"; import { SettingsView } from "../settings/SettingsView"; import { SolutionView } from "../SolutionView"; +import { BoundDisplay } from "../VariableDependentDisplay"; import { useGraphUpdates } from "./ProblemGraphView"; import { useSolvers } from "./SolverProvider"; @@ -57,6 +59,14 @@ export const ProblemDetails = (props: { problemDto: ProblemDto }) => { (s) => s.id === props.problemDto.solverId ); + function getBound(problemTypeId: string, problemId: string) { + fetchProblemBounds(problemTypeId, problemId).then((res) => { + if (!res.error) { + updateProblem(props.problemDto.id); + } + }); + } + return (