Skip to content

Commit

Permalink
Merge pull request #58 from erik-sth/57-distribution-alg-fallback-str…
Browse files Browse the repository at this point in the history
…ategys

Added sending feedback if alg found solution.
  • Loading branch information
erik-sth authored Nov 4, 2023
2 parents 8cbba5a + 2b2092a commit 23e5c10
Show file tree
Hide file tree
Showing 5 changed files with 362 additions and 11 deletions.
12 changes: 7 additions & 5 deletions src/alg/TimeDistribution.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,15 @@ function main(
students: Student[],
project: Project,
polls: PollQuestion[]
): Item[] {
let groups = buildGroupsByPaths(polls, students);
): boolean {
const groups = buildGroupsByPaths(polls, students);
const g = createGraph(items);
groups = findPathsForTheGroups(groups, items, g, project);
distributeStudentsToPaths(items, groups);
const res = findPathsForTheGroups(groups, items, g, project);
if (!res) return false;
const res2 = distributeStudentsToPaths(items, groups);
if (!res2) return false;
allocateGroupsToItems(items, groups, project);
return items;
return true;
}

export { main, getVotingIds };
11 changes: 9 additions & 2 deletions src/alg/TimeDistribution/DistributeStudents.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,26 +10,33 @@ function distributeStudentsToPaths(items: Item[], groups: Group[]) {
relevantItems,
amountRelevantStudents(changableGroups)
);
distributeWithMinimumCapacity(changableGroups, relevantItems);
return distributeWithMinimumCapacity(changableGroups, relevantItems);
}

function distributeWithMinimumCapacity(
changableGroups: Group[],
relevantItems: Item[]
) {
let working = true;
changableGroups.forEach((group) => {
let amountStudents = group.studentIds.length;
group.paths.forEach((path) => {
const minCapacity = Math.min(
...path.path.map((pathItem) => pathItem.updatedGroupCapacity)
...path.path.map((pathItem) => pathItem.updatedGroupCapacity),
group.studentIds.length
);
path.valueForTestingStudentDistribution = minCapacity;
amountStudents -= minCapacity;
relevantItems.forEach((item) => {
if (path.path.includes(item)) {
item.updatedGroupCapacity -= minCapacity;
}
});
});

if (amountStudents > 0) working = false;
});
return working;
}

function amountRelevantStudents(changableGroups: Group[]) {
Expand Down
8 changes: 5 additions & 3 deletions src/alg/TimeDistribution/FindPaths.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,18 @@ function findPathsForTheGroups(
g: DirectedGraph<Item>,
project: Project,
requiredIds: Set<string> = new Set<string>(getDefaultIds(project))
): Group[] {
): boolean {
const entries = g.getNodesWithoutIngoingEdges();
groups.forEach((group) => {
const ids = new Set([...requiredIds, ...group.requiredEvents]);
entries.forEach((entry: GraphNode<Item>) => {
dfs(entry, ids, [], group.requiredEvents, group, items);
});
if (group.paths.length == 0) {
return false;
}
});

return groups;
return true;
}

function dfs(
Expand Down
Loading

0 comments on commit 23e5c10

Please sign in to comment.