Skip to content

Commit

Permalink
fix: Handle lists of problems with subroutines properly by working wi…
Browse files Browse the repository at this point in the history
…th all subroutines
  • Loading branch information
Elscrux committed Sep 3, 2024
1 parent 238af3e commit 09cd0e7
Showing 1 changed file with 38 additions and 7 deletions.
45 changes: 38 additions & 7 deletions src/components/solvers/Graph/ProblemGraphView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import { ProblemDto } from "../../../api/data-model/ProblemDto";
import { ProblemSolverInfo } from "../../../api/data-model/ProblemSolverInfo";
import { ProblemState } from "../../../api/data-model/ProblemState";
import { SubRoutineDefinitionDto } from "../../../api/data-model/SubRoutineDefinitionDto";
import { SubRoutineReferenceDto } from "../../../api/data-model/SubRoutineReferenceDto";
import { fetchProblem, patchProblem } from "../../../api/ToolboxAPI";
import { SolutionView } from "../SolutionView";
import { LevelInfo, ProblemNode, ProblemNodeData } from "./ProblemNode";
Expand Down Expand Up @@ -387,14 +388,44 @@ export const ProblemGraphView = (props: ProblemGraphViewProps) => {
console.log(node.id, node.position.x, node.position.y);

// Solver id and thus sub problems are the same for all problems, so we can just use the first one
const subProblems = node.data.problemDtos[0].subProblems;
node.data.problemDtos;
let subProblemsPerType: Map<
SubRoutineDefinitionDto,
SubRoutineReferenceDto[]
> = new Map<SubRoutineDefinitionDto, SubRoutineReferenceDto[]>();

// Collect specific sub problems of all subproblems by sub routine
node.data.problemDtos[0].subProblems.forEach((subRoutineReference, i) => {
for (let problemDto of node.data.problemDtos) {
const references = subProblemsPerType.get(
subRoutineReference.subRoutine
);
if (references) {
subProblemsPerType.set(
subRoutineReference.subRoutine,
references.concat(problemDto.subProblems)
);
} else {
subProblemsPerType.set(subRoutineReference.subRoutine, [
problemDto.subProblems[i],
]);
}
}
});

// Update sub-problem nodes
for (let subProblem of subProblems) {
for (let subProblems of Array.from(subProblemsPerType.values())) {
// This can use the first sub problem as the relevant parts
// (the definition and type of the sub-problem) will be the same for all
const subRoutineReference = subProblems[0].subRoutine;

// Fetch all sub problems to update the sub-problem nodes
Promise.all(
subProblem.subProblemIds.map((subProblemId) =>
fetchProblem(subProblem.subRoutine.typeId, subProblemId)
)
subProblems
.flatMap((x) => x.subProblemIds)
.map((subProblemId) =>
fetchProblem(subRoutineReference.typeId, subProblemId)
)
).then((subProblemDtos) => {
// Create sub problem nodes per used solver
const problemsPerSolver = groupBySolver(subProblemDtos);
Expand All @@ -403,7 +434,7 @@ export const ProblemGraphView = (props: ProblemGraphViewProps) => {
let unusedChildNodes = getChildNodes(
nodes,
node,
subProblem.subRoutine.typeId
subRoutineReference.typeId
);

let entries = Array.from(problemsPerSolver.entries());
Expand All @@ -426,7 +457,7 @@ export const ProblemGraphView = (props: ProblemGraphViewProps) => {
}

const problemNodeIdentifier: ProblemNodeIdentifier = {
subRoutineDefinitionDto: subProblem.subRoutine,
subRoutineDefinitionDto: subRoutineReference,
solverId: solverId,
};

Expand Down

0 comments on commit 09cd0e7

Please sign in to comment.