diff --git a/src/api/ToolboxAPI.ts b/src/api/ToolboxAPI.ts index ef8fa2d..3218869 100644 --- a/src/api/ToolboxAPI.ts +++ b/src/api/ToolboxAPI.ts @@ -151,3 +151,40 @@ 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(), + (reason) => { + return { error: reason }; + } + ); +} + +export async function fetchProblemBoundComparison( + problemTypeId: string, + problemId: string +) { + return fetch( + `${baseUrl()}/problems/${problemTypeId}/${problemId}/bound/compare`, + { + method: "GET", + headers: { + "Content-Type": "application/json", + }, + } + ).then( + (response) => response.json(), + (reason) => { + return { error: reason }; + } + ); +} diff --git a/src/api/data-model/BoundComparisonDto.ts b/src/api/data-model/BoundComparisonDto.ts new file mode 100644 index 0000000..f310812 --- /dev/null +++ b/src/api/data-model/BoundComparisonDto.ts @@ -0,0 +1,16 @@ +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/BoundDto.ts b/src/api/data-model/BoundDto.ts new file mode 100644 index 0000000..bbb991f --- /dev/null +++ b/src/api/data-model/BoundDto.ts @@ -0,0 +1,15 @@ +import { BoundType } from "./BoundType"; + +export interface BoundDto { + value: number; + boundType: BoundType; + executionTime: number; +} + +export function getInvalidBoundDto(): BoundDto { + return { + value: NaN, + boundType: BoundType.UPPER, + executionTime: -1, + }; +} 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..db32f80 100644 --- a/src/api/data-model/ProblemDto.ts +++ b/src/api/data-model/ProblemDto.ts @@ -1,3 +1,7 @@ +import { + BoundComparisonDto, + getInvalidBoundComparisonDto, +} from "./BoundComparisonDto"; import { ProblemState } from "./ProblemState"; import { getInvalidSolutionObject, SolutionObject } from "./SolutionObject"; import { SolverSetting } from "./SolverSettings"; @@ -8,6 +12,7 @@ export interface ProblemDto { typeId: string; input: T; solution: SolutionObject; + bound: BoundComparisonDto; state: ProblemState; solverId?: string; solverSettings: SolverSetting[]; @@ -21,6 +26,7 @@ export function getInvalidProblemDto(): ProblemDto { id: "", input: {} as T, solution: getInvalidSolutionObject(), + bound: getInvalidBoundComparisonDto(), solverId: "", solverSettings: [], state: ProblemState.READY_TO_SOLVE, diff --git a/src/components/solvers/Graph/ProblemDetails.tsx b/src/components/solvers/Graph/ProblemDetails.tsx index 0a206c7..5962cac 100644 --- a/src/components/solvers/Graph/ProblemDetails.tsx +++ b/src/components/solvers/Graph/ProblemDetails.tsx @@ -9,11 +9,13 @@ import { Textarea, VStack, } from "@chakra-ui/react"; -import { ReactNode } from "react"; +import { ReactNode, useState } 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"; @@ -49,6 +51,7 @@ function getAccordionItem(label: string, content: ReactNode) { export const ProblemDetails = (props: { problemDto: ProblemDto }) => { const { solvers, getSolvers } = useSolvers(); const { updateProblem } = useGraphUpdates(); + const [boundError, setBoundError] = useState(false); // Update solvers in case they are not loaded yet if (!solvers[props.problemDto.typeId]) getSolvers(props.problemDto.typeId); @@ -57,6 +60,16 @@ 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) { + setBoundError(true); + } else { + updateProblem(props.problemDto.id); + } + }); + } + return (