Skip to content

Commit

Permalink
refac/ remove console.log, fix server file and workflow parser
Browse files Browse the repository at this point in the history
  • Loading branch information
brunolnetto committed Feb 15, 2022
1 parent e7cc836 commit 11ac57d
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 33 deletions.
12 changes: 5 additions & 7 deletions data-structures/graph/Graph.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import Iter, { cycle } from 'es-iter';
import Iter from 'es-iter';
import _ from 'lodash';

import stronglyConnectedComponents from '../../algorithms/strongly-connected-components/stronglyConnectedComponents.js';
Expand Down Expand Up @@ -205,7 +205,7 @@ export default class Graph {

return vertexKeys
}

/**
* @param {string} vertexKey
* @returns GraphVertex
Expand Down Expand Up @@ -1215,8 +1215,8 @@ export default class Graph {
acyclicPaths(from, to) {
const verticesKeystoIndices = this.getVerticesKeystoIndices();

const from_index = verticesKeystoIndices[from.getKey()];
const to_index = verticesKeystoIndices[to.getKey()];
const from_index = verticesKeystoIndices[from];
const to_index = verticesKeystoIndices[to];

const n_vertices = this.getNumVertices();

Expand Down Expand Up @@ -1301,10 +1301,8 @@ export default class Graph {
let can_increment_route=_.intersection(acyclic_path_keys, out_in_keys).length===2 &&
start_node_index >= finish_node_index
if(can_increment_route){
console.log(out_in_keys)
out_in_flow=this.convertVerticesKeystoIndexes(out_in_keys)
console.log(out_in_flow)


new_route = [].concat(acyclic_path_indexes.slice(0, start_node_index+1),
out_in_flow.slice(1, -1),
acyclic_path_indexes.slice(finish_node_index))
Expand Down
10 changes: 5 additions & 5 deletions server.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import fs from 'fs';

import {
parseBlueprintToGraph,
fromStartToFinishCombsAcyclicPaths,
fromStartToFinishCombsAllPaths,
} from './utils/workflow/parsers.js';

import { cartesianProduct } from './utils/arrays/arrays.js'
Expand Down Expand Up @@ -46,14 +46,14 @@ app.get('/', (req, res) => {
// let graph_i = parseBlueprintToGraph(blueprint_i);
descriptions.push(fromStartToFinishCombsAcyclicPaths(blueprint_i));
}

res.send(descriptions);
} else {
const fname = bps_root + blueprint_fname;
const blueprint_i = require(fname);

console.log(blueprint_i['blueprint_spec']['lanes'])
const graph = parseBlueprintToGraph(blueprint_i);
const route_describe = fromStartToFinishCombsAcyclicPaths(blueprint_i);
const route_describe = fromStartToFinishCombsAllPaths(blueprint_i);

let start_nodes_indexes=graph.orphanNodes();
let finish_nodes_indexes=graph.looseNodes();
Expand All @@ -67,7 +67,7 @@ app.get('/', (req, res) => {
paths.push(graph.allPaths(start_node, finish_node))
}

res.send(paths);
res.send(route_describe);
}

});
Expand Down
42 changes: 21 additions & 21 deletions utils/workflow/parsers.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,13 +78,13 @@ export const nodeToLane = (blueprint) => {

export const nodeRouteToLaneRoute = (
node_route,
indexes_to_vertices,
vertices_indices_to_keys,
node_id_to_lane,
) => {
const lane_route = [];

for (const vertex_j of node_route) {
const lane_vertex_j = node_id_to_lane[indexes_to_vertices[vertex_j]];
const lane_vertex_j = node_id_to_lane[vertices_indices_to_keys[vertex_j]];

if (lane_route.length == 0) {
lane_route.push(lane_vertex_j);
Expand All @@ -98,55 +98,55 @@ export const nodeRouteToLaneRoute = (
return lane_route;
};

export const fromStartToFinishAcyclicPaths = (blueprint, start_key, finish_key) => {
export const fromStartToFinishAllPaths = (blueprint, start_key, finish_key) => {
const bp_graph = parseBlueprintToGraph(blueprint);
const indexes_to_vertices = bp_graph.getIndicesToVertices();
const node_id_to_lane = nodeToLane(blueprint);

const looseNodes = bp_graph.looseNodes();
const orphanNodes = bp_graph.orphanNodes();
const vertices_keys_to_indices = bp_graph.getVerticesIndices();
const vertices_keys_to_indices = bp_graph.getVerticesKeystoIndices();
const vertices_indices_to_keys = bp_graph.getVerticesIndicestoKeys();

const start_id = vertices_keys_to_indices[start_key];
const finish_id = vertices_keys_to_indices[finish_key];
const start_index = vertices_keys_to_indices[start_key];
const finish_index = vertices_keys_to_indices[finish_key];

let is_undefined=false;
if (start_id === undefined) {
console.warn(`Warning: Claimed start vertex id ${start_key} is not available within nodes`);
if (start_index === undefined) {
console.warn(`Warning: Claimed start vertex key ${start_key} is not available within nodes`);
is_undefined=true;
}

if (finish_id === undefined) {
console.warn(`Warning: Claimed finish vertex id ${finish_key} is not available within nodes`);
if (finish_index === undefined) {
console.warn(`Warning: Claimed finish vertex key ${finish_key} is not available within nodes`);
is_undefined=true;
}

if(is_undefined){
return [];
}

if (getAllIndexes(orphanNodes, start_id).length === 0) {
console.warn(`Vertex id ${start_id} is not a start node! Detected start nodes: ${orphanNodes}`);
if (getAllIndexes(orphanNodes, start_index).length === 0) {
console.warn(`Vertex id ${start_index} is not a start node! Detected start nodes: ${orphanNodes}`);

return [];
}

if (getAllIndexes(looseNodes, finish_id).length === 0) {
console.warn(`Vertex id ${finish_id} is not a finish node! Detected finish nodes: ${looseNodes}`);
if (getAllIndexes(looseNodes, finish_index).length === 0) {
console.warn(`Vertex id ${finish_index} is not a finish node! Detected finish nodes: ${looseNodes}`);

return [];
}

const routes = bp_graph.acyclicPaths(start_key, finish_key);
const routes = bp_graph.allPaths(start_key, finish_key);
const route_describe = {
length: routes.length,
routes: [],
};
let lane_route_i = [];

for (const i of Iter.range(routes.length)) {
lane_route_i = nodeRouteToLaneRoute(routes[i], indexes_to_vertices, node_id_to_lane);

lane_route_i = nodeRouteToLaneRoute(routes[i], vertices_indices_to_keys, node_id_to_lane);
route_describe.routes.push(
{
nodes_path: routes[i],
Expand All @@ -158,7 +158,7 @@ export const fromStartToFinishAcyclicPaths = (blueprint, start_key, finish_key)
return route_describe;
};

export const fromStartToFinishCombsAcyclicPaths = (blueprint) => {
export const fromStartToFinishCombsAllPaths = (blueprint) => {
const sf_nodes = startAndFinishNodes(blueprint);

const acyclic_paths = {};
Expand All @@ -171,7 +171,7 @@ export const fromStartToFinishCombsAcyclicPaths = (blueprint) => {
finishNode = sf_nodes.finish_nodes[j];

const label = `${startNode}_${finishNode}`;
acyclic_paths[label] = fromStartToFinishAcyclicPaths(blueprint, startNode, finishNode);
acyclic_paths[label] = fromStartToFinishAllPaths(blueprint, startNode, finishNode);
}
}

Expand Down

0 comments on commit 11ac57d

Please sign in to comment.