diff --git a/src/main/DirectedEdge.ts b/src/main/DirectedEdge.ts index 8850afe..db19bf4 100644 --- a/src/main/DirectedEdge.ts +++ b/src/main/DirectedEdge.ts @@ -22,7 +22,7 @@ export class DirectedEdge extends Edge { * @param vertexOne * @param vertexTwo */ - public constructor(vertexOne: IVertex, vertexTwo: IVertex) { - super(vertexOne, vertexTwo); + public constructor(vertexOne: IVertex, vertexTwo: IVertex, name: string = undefined, weightLabel: string = undefined, isDirected:boolean = true) { + super(vertexOne, vertexTwo, name, weightLabel, isDirected); } } \ No newline at end of file diff --git a/src/main/DirectedGraph.ts b/src/main/DirectedGraph.ts index aa33798..bd960e0 100644 --- a/src/main/DirectedGraph.ts +++ b/src/main/DirectedGraph.ts @@ -6,6 +6,7 @@ import {UndirectedGraph} from "./UndirectedGraph"; import {SccBuilder} from "../algorithms/SccBuilder"; import {IGraph} from "../types/IGraph"; import {IEdge} from "../types/IEdge"; +import {forEach} from "lodash"; /** * Directed graph @@ -16,8 +17,8 @@ export class DirectedGraph extends Graph { /** * @constructor */ - public constructor() { - super(true); + public constructor(directed: boolean = true) { + super(directed); } /** @@ -26,8 +27,24 @@ export class DirectedGraph extends Graph { * @param vertexTwo * @returns {DirectedEdge} */ - public getEdge(vertexOne: IVertex, vertexTwo: IVertex): DirectedEdge[] { - return this.edges.filter(a => a.vertexTwo.equals(vertexTwo) && a.vertexOne.equals(vertexOne)); + public getEdge(vertexOne: IVertex, vertexTwo: IVertex): DirectedEdge[]{ + + let e:DirectedEdge; + + let i:number=0; + let result:DirectedEdge[] =[]; + + for (i=0; i a.vertexTwo.name === vertexTwo.name && a.vertexOne.name == vertexOne.name); + + return result; } public buildSCC(): IGraph[] { @@ -39,13 +56,13 @@ export class DirectedGraph extends Graph { * @returns {DirectedGraph} */ public clone(): DirectedGraph { - const clone = new DirectedGraph(); + const clone = new DirectedGraph(true); this.vertices.forEach(v => clone.addVertex(v.clone())); for (const edge of this.edges) { - const v1 = clone.vertices.filter(edge.vertexOne.equals)[0]; //Single? - const v2 = clone.vertices.filter(edge.vertexTwo.equals)[0]; - clone.addEdge(new DirectedEdge(v1, v2)); + // const v1 = clone.vertices.filter(edge.vertexOne.equals)[0]; //Single? + // const v2 = clone.vertices.filter(edge.vertexTwo.equals)[0]; + clone.addEdge(new DirectedEdge(edge.vertexOne, edge.vertexTwo, edge.name, edge.weightLabel, edge.isDirected)); } return clone; diff --git a/src/main/Graph.ts b/src/main/Graph.ts index 9da4945..91bd80f 100644 --- a/src/main/Graph.ts +++ b/src/main/Graph.ts @@ -9,7 +9,7 @@ import {UndirectedGraph} from "./UndirectedGraph"; /** @classdesc * Graph implementation of the IGraph interface */ -export class Graph implements IGraph { +export class Graph implements IGraph { /** @property * @private * Mark shows whether graph edges are directed or not */ @@ -346,7 +346,7 @@ export class Graph implements IGraph { * Get vertex's degree */ public getVertexDegree(vertex: Vertex): number { - return this.edges.filter((e: Edge) => (e.vertexOne === vertex) || (e.vertexTwo === vertex)).length; + return this.edges.filter((e: IEdge) => (e.vertexOne === vertex) || (e.vertexTwo === vertex)).length; } /**