|
|
@@ -2,7 +2,6 @@ import CycleRemoveStepError from "../../errors/optimizer/CycleRemoveStepError.js
|
|
|
import Edge from "../../graph/Edge.js";
|
|
|
import Graph from "../../graph/Graph.js";
|
|
|
import Node from "../../graph/Node.js";
|
|
|
-import GraphService from "../../services/GraphService.js";
|
|
|
import AlgorithmStep from "../AlgorithmStep.js";
|
|
|
import { SiguiyamaContext } from "./SiguiyamaContext.js";
|
|
|
|
|
|
@@ -10,12 +9,6 @@ import { SiguiyamaContext } from "./SiguiyamaContext.js";
|
|
|
* Greedy Cycle Removal Algoirthm
|
|
|
*/
|
|
|
export default class CycleRemoveStep implements AlgorithmStep<SiguiyamaContext> {
|
|
|
- private readonly _graphService: GraphService;
|
|
|
-
|
|
|
- public constructor(graphService: GraphService) {
|
|
|
- this._graphService = graphService;
|
|
|
- }
|
|
|
-
|
|
|
run(context: SiguiyamaContext): void {
|
|
|
const { graph } = context;
|
|
|
if(!graph)
|
|
|
@@ -34,13 +27,13 @@ export default class CycleRemoveStep implements AlgorithmStep<SiguiyamaContext>
|
|
|
const feedbackSet: NonNullable<SiguiyamaContext["feedbackSet"]> = [];
|
|
|
|
|
|
for(const node of nodes) {
|
|
|
- const isSource = this._graphService.isSourceNode(graph, node.id);
|
|
|
+ const isSource = graph.isSourceNode(node.id);
|
|
|
if(isSource) {
|
|
|
l.push(node);
|
|
|
continue;
|
|
|
}
|
|
|
|
|
|
- const isSink = this._graphService.isSinkNode(graph, node.id);
|
|
|
+ const isSink = graph.isSinkNode(node.id);
|
|
|
if(isSink) {
|
|
|
r.unshift(node);
|
|
|
continue;
|
|
|
@@ -74,8 +67,8 @@ export default class CycleRemoveStep implements AlgorithmStep<SiguiyamaContext>
|
|
|
}
|
|
|
|
|
|
private calculateScore(graph: Graph<Node, Edge<Node>>, node: Node) : number {
|
|
|
- const outDegree = this._graphService.getNodeOutDegree(graph, node.id);
|
|
|
- const inDegree = this._graphService.getNodeInDegree(graph, node.id);
|
|
|
+ const outDegree = graph.getNodeOutputs(node.id).length;
|
|
|
+ const inDegree = graph.getNodeInputs(node.id).length;
|
|
|
|
|
|
return outDegree - inDegree;
|
|
|
}
|