Skip to content

Commit

Permalink
Merge pull request #53 from ProvideQ/feat/solver-settings
Browse files Browse the repository at this point in the history
 Adds solver specific settings
  • Loading branch information
Elscrux authored Oct 11, 2024
2 parents 30fa3bf + bdf0e09 commit 125bac5
Show file tree
Hide file tree
Showing 13 changed files with 371 additions and 235 deletions.
48 changes: 26 additions & 22 deletions src/api/ToolboxAPI.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { getInvalidProblemDto, ProblemDto } from "./data-model/ProblemDto";
import { ProblemSolverInfo } from "./data-model/ProblemSolverInfo";
import { ProblemState } from "./data-model/ProblemState";
import { SolverSetting } from "./data-model/SolverSettings";
import { SubRoutineDefinitionDto } from "./data-model/SubRoutineDefinitionDto";

/**
Expand Down Expand Up @@ -61,11 +62,14 @@ export async function postProblem<T>(
export async function patchProblem<T>(
problemTypeId: string,
problemId: string,
updateParameters: { input?: any; solverId?: string; state?: ProblemState }
updateParameters: {
input?: any;
solverId?: string;
state?: ProblemState;
solverSettings?: SolverSetting[];
}
): Promise<ProblemDto<T>> {
let url = `${baseUrl()}/problems/${problemTypeId}/${problemId}`;
console.log(url);
return fetch(url, {
return fetch(`${baseUrl()}/problems/${problemTypeId}/${problemId}`, {
method: "PATCH",
headers: {
"Content-Type": "application/json",
Expand Down Expand Up @@ -105,9 +109,7 @@ export async function fetchSubRoutines(
solverId: string
): Promise<SubRoutineDefinitionDto[]> {
return fetch(
`${baseUrl()}/sub-routines/${problemTypeId}?${new URLSearchParams({
id: solverId,
})}`,
`${baseUrl()}/solvers/${problemTypeId}/${solverId}/sub-routines`,
{
method: "GET",
headers: {
Expand All @@ -123,18 +125,20 @@ export async function fetchSubRoutines(
});
}

// export async function fetchMetaSolverSettings(
// problemTypeId: string
// ): Promise<MetaSolverSetting[]> {
// return fetch(`${baseUrl()}/meta-solver/settings/${problemTypeId}`, {
// method: "GET",
// headers: {
// "Content-Type": "application/json",
// },
// })
// .then((response) => response.json())
// .catch((reason) => {
// console.log(reason);
// return [];
// });
// }
export async function fetchSolverSettings(
problemTypeId: string,
solverId: string
): Promise<[]> {
return fetch(`${baseUrl()}/solvers/${problemTypeId}/${solverId}/settings`, {
method: "GET",
headers: {
"Content-Type": "application/json",
},
})
.then((response) => response.json())
.catch((reason) => {
console.error(reason);
alert(`Could not retrieve subroutines of solver ${solverId}.`);
return [];
});
}
30 changes: 0 additions & 30 deletions src/api/data-model/MetaSolverSettings.ts

This file was deleted.

3 changes: 3 additions & 0 deletions src/api/data-model/ProblemDto.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { ProblemState } from "./ProblemState";
import { getInvalidSolutionObject, SolutionObject } from "./SolutionObject";
import { SolverSetting } from "./SolverSettings";
import { SubRoutineReferenceDto } from "./SubRoutineReferenceDto";

export interface ProblemDto<T> {
Expand All @@ -9,6 +10,7 @@ export interface ProblemDto<T> {
solution: SolutionObject;
state: ProblemState;
solverId?: string;
solverSettings: SolverSetting[];
subProblems: SubRoutineReferenceDto[];
error: string;
}
Expand All @@ -20,6 +22,7 @@ export function getInvalidProblemDto<T>(): ProblemDto<T> {
input: {} as T,
solution: getInvalidSolutionObject(),
solverId: "",
solverSettings: [],
state: ProblemState.READY_TO_SOLVE,
subProblems: [],
typeId: "",
Expand Down
33 changes: 33 additions & 0 deletions src/api/data-model/SolverSettings.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
export enum SolverSettingType {
INTEGER = "INTEGER",
DOUBLE = "DOUBLE",
CHECKBOX = "CHECKBOX",
TEXT = "TEXT",
SELECT = "SELECT",
}

export interface SolverSetting {
name: string;
description: string;
type: SolverSettingType;
required: boolean;
}

export interface RangeSetting extends SolverSetting {
min: number;
max: number;
value: number;
}

export interface CheckboxSetting extends SolverSetting {
state: boolean;
}

export interface TextSetting extends SolverSetting {
text: string;
}

export interface SelectSetting extends SolverSetting {
options: string[];
selectedOption: string;
}
23 changes: 19 additions & 4 deletions src/components/solvers/Graph/ProblemDetails.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@ import {
import { ReactNode } from "react";
import { ProblemDto } from "../../../api/data-model/ProblemDto";
import { ProblemState } from "../../../api/data-model/ProblemState";
import { SettingsView } from "../settings/SettingsView";
import { SolutionView } from "../SolutionView";
import { useGraphUpdates } from "./ProblemGraphView";
import { useSolvers } from "./SolverProvider";

function getHumanReadableState(state: ProblemState) {
Expand Down Expand Up @@ -46,22 +48,35 @@ function getAccordionItem(label: string, content: ReactNode) {

export const ProblemDetails = (props: { problemDto: ProblemDto<any> }) => {
const { solvers, getSolvers } = useSolvers();
const { updateProblem } = useGraphUpdates();

// Update solvers in case they are not loaded yet
if (!solvers[props.problemDto.typeId]) getSolvers(props.problemDto.typeId);

const solver = solvers[props.problemDto.typeId]?.find(
(s) => s.id === props.problemDto.solverId
);

return (
<VStack gap="20px" align="start">
<Textarea readOnly resize="vertical" value={props.problemDto.input} />
<Text>
<b>Status:</b> {getHumanReadableState(props.problemDto.state)}
</Text>
<Text>
<b>Solver:</b>{" "}
{solvers[props.problemDto.typeId]?.find(
(s) => s.id === props.problemDto.solverId
)?.name ?? "-"}
<b>Solver:</b> {solver?.name ?? "-"}
</Text>
{solver && (
<VStack width="100%" align="stretch">
<Text>Solver Settings:</Text>
<SettingsView
problemDto={props.problemDto}
settingsChanged={(settings) => {
updateProblem(props.problemDto.id);
}}
/>
</VStack>
)}
{props.problemDto.subProblems.length === 0 ? (
<b>No subroutines</b>
) : (
Expand Down
179 changes: 0 additions & 179 deletions src/components/solvers/SettingsView.tsx

This file was deleted.

Loading

0 comments on commit 125bac5

Please sign in to comment.