Skip to content

Commit

Permalink
Merge pull request #57 from ProvideQ/release/0.4.0
Browse files Browse the repository at this point in the history
ProvideQ Release 0.4.0
  • Loading branch information
koalamitice authored Nov 11, 2024
2 parents 802fd36 + 7481350 commit 6e18d91
Show file tree
Hide file tree
Showing 69 changed files with 3,377 additions and 1,748 deletions.
4 changes: 3 additions & 1 deletion .prettierrc.json
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
{}
{
"plugins": ["prettier-plugin-organize-imports"]
}
33 changes: 1 addition & 32 deletions __tests__/converter/dimacs/DimacsLogicalExpression.spec.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import each from "jest-each";
import { regexBlank } from "../../../src/converter/dimacs/Syntax/CommonSyntax";
import { DimacsParser } from "../../../src/converter/dimacs/DimacsParser";
import { regexBlank } from "../../../src/converter/dimacs/Syntax/CommonSyntax";
import { regexComment } from "../../../src/converter/dimacs/Syntax/DimacsSyntax";
import { LogicalExpressionParser } from "../../../src/converter/dimacs/LogicalExpressionParser";
import { regexNOT } from "../../../src/converter/dimacs/Syntax/LogicalExpressionSyntax";

function isEquivalentLogicalExpression(f1: string, f2: string) {
Expand All @@ -19,36 +18,6 @@ function isEquivalentDimacs(f1: string, f2: string) {

describe("Parsing", () => {
let dimacsParser = new DimacsParser();
let logicalExpressionParser = new LogicalExpressionParser();

each([
[
"((1 or 2 or not 3) and (!4 and (not 5 and 6)) and 3 and (7 or 2))",
"c First comment\nc Some Comment\nc 1 => 1\np sat 7\n*(+( 1 2 -3 )*( -4 *( -5 6 )) 3 +( 7 2 ))",
],
[
"(1 or (2 and 3) or (((1 and 4) or 5) and 6))",
"p sat 6\n+(1 *(2 3)*(+(*(1 4) 5) 6))",
],
[
"(((1 and not 2 and 3 and 4) or 3) and 5)",
"c Sample DIMACS .sat file\np sat 5\n*(+(*(1 -2 3 4) 3) 5)",
],
["((1 and not 2) or 3)", "p sat 3\n+(*(1 -2) 3)"],
["((1 and 2) or not 3)", "p sat 3\n+(*(1 2) -3)"],
]).test(
"parsing bi-directional",
(logicalExpression: string, dimacs: string) => {
isEquivalentDimacs(
logicalExpressionParser.parseDimacs(logicalExpression),
dimacs
);
isEquivalentLogicalExpression(
dimacsParser.parseLogicalExpression(dimacs),
logicalExpression
);
}
);

each([
[
Expand Down
10 changes: 4 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "provideq",
"version": "0.3.0",
"version": "0.4.0",
"private": true,
"scripts": {
"dev": "next dev",
Expand All @@ -10,11 +10,7 @@
"format": "prettier --write .",
"test": "jest"
},
"resolutions": {
"d3-interpolate": "2.0.1"
},
"dependencies": {
"@antv/g6": "^4.7.16",
"@chakra-ui/react": "^2.3.1",
"@emotion/react": "11",
"@emotion/styled": "11",
Expand All @@ -26,7 +22,8 @@
"react-dom": "18.2.0",
"react-icons": "^4.4.0",
"react-multi-select-component": "^4.3.4",
"react-simple-code-editor": "^0.13.0"
"react-simple-code-editor": "^0.13.0",
"reactflow": "^11.10.3"
},
"devDependencies": {
"@testing-library/jest-dom": "^5.16.5",
Expand All @@ -40,6 +37,7 @@
"jest": "^29.1.1",
"jest-environment-jsdom": "^29.1.1",
"prettier": "2.8.8",
"prettier-plugin-organize-imports": "^3.2.4",
"typescript": "4.8.2"
}
}
119 changes: 84 additions & 35 deletions src/api/ToolboxAPI.ts
Original file line number Diff line number Diff line change
@@ -1,68 +1,115 @@
import { MetaSolverSetting } from "./data-model/MetaSolverSettings";
import { SubRoutineDefinition } from "./data-model/SubRoutineDefinition";
import { ProblemSolver } from "./data-model/ProblemSolver";
import { Solution } from "./data-model/Solution";
import { SolutionStatus } from "./data-model/SolutionStatus";
import { SolveRequest } from "./data-model/SolveRequest";
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";

/**
* Getter for the base url of the toolbox API.
*/
export const baseUrl = () => process.env.NEXT_PUBLIC_API_BASE_URL;

export async function fetchProblem<T>(
problemTypeId: string,
problemId: string
): Promise<ProblemDto<T>> {
return fetch(`${baseUrl()}/problems/${problemTypeId}/${problemId}`, {
method: "GET",
headers: {
"Content-Type": "application/json",
},
})
.then((response) => response.json())
.then((json) => {
const data = json as ProblemDto<T>;

// Explicitly set solverId to undefined if it is null
if (data.solverId === null) {
data.solverId = undefined;
}

return data;
})
.catch((reason) => {
return {
...getInvalidProblemDto(),
error: `${reason}`,
};
});
}

export async function postProblem<T>(
problemType: string,
solveRequest: SolveRequest<T>
): Promise<Solution> {
return fetch(`${baseUrl()}/solve/${problemType}`, {
problemTypeId: string,
problemRequest: ProblemDto<T>
): Promise<ProblemDto<T>> {
return fetch(`${baseUrl()}/problems/${problemTypeId}`, {
method: "POST",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify(solveRequest),
body: JSON.stringify(problemRequest),
})
.then((response) => response.json())
.then((json) => json as Solution)
.then((json) => json as ProblemDto<T>)
.catch((reason) => {
return {
id: -1,
status: SolutionStatus.INVALID,
solverName: "",
executionMilliseconds: 0,
solutionData: "",
debugData: "",
metaData: "",
...problemRequest,
error: `${reason}`,
};
});
}

export async function patchProblem<T>(
problemTypeId: string,
problemId: string,
updateParameters: {
input?: any;
solverId?: string;
state?: ProblemState;
solverSettings?: SolverSetting[];
}
): Promise<ProblemDto<T>> {
return fetch(`${baseUrl()}/problems/${problemTypeId}/${problemId}`, {
method: "PATCH",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify(updateParameters),
})
.then((response) => response.json())
.then((json) => json as ProblemDto<T>)
.catch((reason) => {
return {
...getInvalidProblemDto(),
error: `${reason}`,
};
});
}

export async function fetchSolvers(
problemType: string
): Promise<ProblemSolver[]> {
return fetch(`${baseUrl()}/solvers/${problemType}`, {
problemTypeId: string
): Promise<ProblemSolverInfo[]> {
return fetch(`${baseUrl()}/solvers/${problemTypeId}`, {
method: "GET",
headers: {
"Content-Type": "application/json",
},
})
.then((response) => response.json())
.then((json) => json as ProblemSolver[])
.then(async (response) => response.json())
.then((json) => json as ProblemSolverInfo[])
.catch((reason) => {
console.error(reason);
alert(`Could not retrieve solvers of type ${problemType}.`);
alert(`Could not retrieve solvers of type ${problemTypeId}.`);
return [];
});
}

export async function fetchSubRoutines(
problemType: string,
problemTypeId: string,
solverId: string
): Promise<SubRoutineDefinition[]> {
): Promise<SubRoutineDefinitionDto[]> {
return fetch(
`${baseUrl()}/sub-routines/${problemType}?${new URLSearchParams({
id: solverId,
})}`,
`${baseUrl()}/solvers/${problemTypeId}/${solverId}/sub-routines`,
{
method: "GET",
headers: {
Expand All @@ -78,18 +125,20 @@ export async function fetchSubRoutines(
});
}

export async function fetchMetaSolverSettings(
problemType: string
): Promise<MetaSolverSetting[]> {
return fetch(`${baseUrl()}/meta-solver/settings/${problemType}`, {
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.log(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.

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

export interface ProblemDto<T> {
id: string;
typeId: string;
input: T;
solution: SolutionObject;
state: ProblemState;
solverId?: string;
solverSettings: SolverSetting[];
subProblems: SubRoutineReferenceDto[];
error: string;
}

export function getInvalidProblemDto<T>(): ProblemDto<T> {
return {
error: "",
id: "",
input: {} as T,
solution: getInvalidSolutionObject(),
solverId: "",
solverSettings: [],
state: ProblemState.READY_TO_SOLVE,
subProblems: [],
typeId: "",
};
}

export function canProblemSolverBeUpdated(problem: ProblemDto<any>): boolean {
return (
problem.state === ProblemState.NEEDS_CONFIGURATION ||
problem.state === ProblemState.READY_TO_SOLVE
);
}
4 changes: 0 additions & 4 deletions src/api/data-model/ProblemSolver.ts

This file was deleted.

4 changes: 4 additions & 0 deletions src/api/data-model/ProblemSolverInfo.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
export interface ProblemSolverInfo {
id: string;
name: string;
}
6 changes: 6 additions & 0 deletions src/api/data-model/ProblemState.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
export enum ProblemState {
NEEDS_CONFIGURATION = "NEEDS_CONFIGURATION",
READY_TO_SOLVE = "READY_TO_SOLVE",
SOLVING = "SOLVING",
SOLVED = "SOLVED",
}
12 changes: 0 additions & 12 deletions src/api/data-model/Solution.ts

This file was deleted.

26 changes: 26 additions & 0 deletions src/api/data-model/SolutionObject.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import { SolutionStatus } from "./SolutionStatus";

export interface SolutionObject {
/**
* UUID of the solution.
*/
id: string;
status: SolutionStatus;
metaData: string;
solutionData: any;
debugData: string;
solverName: string;
executionMilliseconds: number;
}

export function getInvalidSolutionObject(): SolutionObject {
return {
id: "",
status: SolutionStatus.INVALID,
metaData: "",
solutionData: undefined,
debugData: "",
solverName: "",
executionMilliseconds: -1,
};
}
7 changes: 4 additions & 3 deletions src/api/data-model/SolutionStatus.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
export enum SolutionStatus {
INVALID,
COMPUTING,
SOLVED,
INVALID = "INVALID",
COMPUTING = "COMPUTING",
SOLVED = "SOLVED",
ERROR = "ERROR",
}
Loading

0 comments on commit 6e18d91

Please sign in to comment.