Skip to content

Commit 80d66d7

Browse files
committed
Fix graph algs with URL input
1 parent da412b3 commit 80d66d7

File tree

12 files changed

+104
-96
lines changed

12 files changed

+104
-96
lines changed

src/algorithms/controllers/BFS.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,6 @@ export default {
111111
);
112112

113113
const bfs = (s) => {
114-
115114
const Nodes = [s];
116115
// Seen[s] <- True B8
117116
visited[s] = true;

src/algorithms/parameters/ASTParam.js

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import MatrixParam from './helpers/MatrixParam';
44
import '../../styles/Param.scss';
55
import EuclideanMatrixParams from './helpers/EuclideanMatrixParams';
66
import PropTypes from 'prop-types'; // Import this for URL Param
7-
import { withAlgorithmParams } from './helpers/urlHelpers' // Import this for URL Param
7+
import { withAlgorithmParams, addURLGraph } from './helpers/urlHelpers'
88

99
// Note: 'A* Algorithm' currently used in EuclideanMatrixParams.js -
1010
// change both or neither!
@@ -34,28 +34,23 @@ const GRAPH_EGS = [ // XXX think up better examples?
3434
}];
3535
function ASTParam( { mode, xyCoords, edgeWeights, size, start, end, heuristic, min, max } ) {
3636
const [message, setMessage] = useState(null);
37-
const graph_egs = [
38-
{ name: 'URL Input Graph',
39-
size: size || GRAPH_EGS[0].size,
40-
coords: xyCoords || GRAPH_EGS[0].coords,
41-
edges: edgeWeights || GRAPH_EGS[0].edges
42-
}
43-
]
37+
let [start1, size1, graph_egs] =
38+
addURLGraph(GRAPH_EGS, xyCoords, edgeWeights, start, DEFAULT_START);
4439

4540
return (
4641
<>
4742
{/* Matrix input */}
4843
<EuclideanMatrixParams
4944
name="aStar"
5045
mode="find"
51-
defaultSize={ size || DEFAULT_SIZE }
52-
defaultStart={ start || DEFAULT_START }
46+
defaultSize={ size1 }
47+
defaultStart={ start1 }
5348
defaultEnd={ end || DEFAULT_END }
5449
heuristic = { heuristic || DEFAULT_HEUR }
5550
min={ min || 1 }
5651
max={ max || 49 }
5752
symmetric
58-
graphEgs={ graph_egs || GRAPH_EGS }
53+
graphEgs={ graph_egs }
5954
ALGORITHM_NAME={ASTAR}
6055
EXAMPLE={ASTAR_EXAMPLE}
6156
EXAMPLE2={ASTAR_EXAMPLE2}

src/algorithms/parameters/BFSParam.js

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import MatrixParam from './helpers/MatrixParam';
44
import '../../styles/Param.scss';
55
import EuclideanMatrixParams from './helpers/EuclideanMatrixParams';
66
import PropTypes from 'prop-types'; // Import this for URL Param
7-
import { withAlgorithmParams } from './helpers/urlHelpers' // Import this for URL Param
7+
import { withAlgorithmParams, addURLGraph } from './helpers/urlHelpers'
88

99
const DEFAULT_SIZE = 5;
1010
const BFS = 'BFS\'s';
@@ -33,27 +33,22 @@ const GRAPH_EGS = [ // XXX think up better examples?
3333

3434
function BFSParam({ mode, xyCoords, edgeWeights, size, start, end, heuristic, min, max }) {
3535
const [message, setMessage] = useState(null);
36-
const graph_egs = [
37-
{ name: 'URL Input Graph',
38-
size: size || GRAPH_EGS[0].size,
39-
coords: xyCoords || GRAPH_EGS[0].coords,
40-
edges: edgeWeights || GRAPH_EGS[0].edges
41-
}
42-
]
36+
let [start1, size1, graph_egs] =
37+
addURLGraph(GRAPH_EGS, xyCoords, edgeWeights, start, DEFAULT_START);
4338
return (
4439
<>
4540
{/* Matrix input */}
4641
<EuclideanMatrixParams
4742
name="BFS"
4843
mode="find"
49-
defaultSize={ size || DEFAULT_SIZE }
50-
defaultStart={ start || DEFAULT_START }
44+
defaultSize={ size1 }
45+
defaultStart={ start1 }
5146
defaultEnd={ end || DEFAULT_END }
52-
defaultHeur = { heuristic || DEFAULT_HEUR }
47+
defaultHeur = { DEFAULT_HEUR }
5348
min={ min || 1 }
5449
max={ max || 49 }
5550
symmetric
56-
graphEgs={ graph_egs || GRAPH_EGS }
51+
graphEgs={ graph_egs }
5752
ALGORITHM_NAME={BFS}
5853
EXAMPLE={BFS_EXAMPLE}
5954
EXAMPLE2={BFS_EXAMPLE2}

src/algorithms/parameters/DFSParam.js

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import MatrixParam from './helpers/MatrixParam';
44
import '../../styles/Param.scss';
55
import EuclideanMatrixParams from './helpers/EuclideanMatrixParams';
66
import PropTypes from 'prop-types'; // Import this for URL Param
7-
import { withAlgorithmParams } from './helpers/urlHelpers' // Import this for URL Param
7+
import { withAlgorithmParams, addURLGraph } from './helpers/urlHelpers'
88

99
const DEFAULT_SIZE = 5;
1010
const DFS = 'DFS\'s';
@@ -33,26 +33,21 @@ const GRAPH_EGS = [ // XXX think up better examples?
3333

3434
function DFSParam({ mode, xyCoords, edgeWeights, size, start, end, heuristic, min, max }) {
3535
const [message, setMessage] = useState(null);
36-
const graph_egs = [
37-
{ name: 'URL Input Graph',
38-
size: size || GRAPH_EGS[0].size,
39-
coords: xyCoords || GRAPH_EGS[0].coords,
40-
edges: edgeWeights || GRAPH_EGS[0].edges
41-
}
42-
]
36+
let [start1, size1, graph_egs] =
37+
addURLGraph(GRAPH_EGS, xyCoords, edgeWeights, start, DEFAULT_START);
4338
return (
4439
<>
4540
{/* Matrix input */}
4641
<EuclideanMatrixParams
4742
name="DFS"
4843
mode= "find"
49-
defaultSize={ size || DEFAULT_SIZE }
50-
defaultStart={start || DEFAULT_START }
51-
defaultHeur = {heuristic || DEFAULT_HEUR }
44+
defaultSize={ size1 }
45+
defaultStart={ start1 }
5246
defaultEnd={ end || DEFAULT_END }
47+
defaultHeur = {DEFAULT_HEUR }
5348
min={ min || 1 }
5449
max={ max || 49 }
55-
graphEgs={graph_egs || GRAPH_EGS}
50+
graphEgs={graph_egs}
5651
symmetric
5752
ALGORITHM_NAME={DFS}
5853
EXAMPLE={DFS_EXAMPLE}

src/algorithms/parameters/DFSrecParam.js

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import MatrixParam from './helpers/MatrixParam';
44
import '../../styles/Param.scss';
55
import EuclideanMatrixParams from './helpers/EuclideanMatrixParams';
66
import PropTypes from 'prop-types'; // Import this for URL Param
7-
import { withAlgorithmParams } from './helpers/urlHelpers' // Import this for URL Param
7+
import { withAlgorithmParams, addURLGraph } from './helpers/urlHelpers'
88

99
const DEFAULT_SIZE = 5;
1010
const DFSrec = 'DFSrec\'s';
@@ -33,27 +33,22 @@ const GRAPH_EGS = [ // XXX think up better examples?
3333

3434
function DFSrecParam({ mode, xyCoords, edgeWeights, size, start, end, heuristic, min, max }) {
3535
const [message, setMessage] = useState(null);
36-
const graph_egs = [
37-
{ name: 'URL Input Graph',
38-
size: size || GRAPH_EGS[0].size,
39-
coords: xyCoords || GRAPH_EGS[0].coords,
40-
edges: edgeWeights || GRAPH_EGS[0].edges
41-
}
42-
]
36+
let [start1, size1, graph_egs] =
37+
addURLGraph(GRAPH_EGS, xyCoords, edgeWeights, start, DEFAULT_START);
4338

4439
return (
4540
<>
4641
{/* Matrix input */}
4742
<EuclideanMatrixParams
4843
name="DFSrec"
4944
mode="find"
50-
defaultSize={size || DEFAULT_SIZE}
51-
defaultStart={start || DEFAULT_START}
52-
defaultHeur = {heuristic || DEFAULT_HEUR}
45+
defaultSize={ size1 }
46+
defaultStart={ start1 }
47+
defaultHeur = {DEFAULT_HEUR}
5348
defaultEnd={end || DEFAULT_END}
5449
min={min || 1}
5550
max={max || 49}
56-
graphEgs={graph_egs || GRAPH_EGS}
51+
graphEgs={graph_egs}
5752
symmetric
5853
ALGORITHM_NAME={DFSrec}
5954
EXAMPLE={DFSrec_EXAMPLE}

src/algorithms/parameters/DIJKParam.js

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,7 @@ import React, { useState } from 'react';
33
import '../../styles/Param.scss';
44
import EuclideanMatrixParams from './helpers/EuclideanMatrixParams';
55
import PropTypes from 'prop-types'; // Import this for URL Param
6-
import { withAlgorithmParams } from './helpers/urlHelpers' // Import this for URL Param
7-
6+
import { withAlgorithmParams, addURLGraph } from './helpers/urlHelpers'
87

98
const DEFAULT_START = 5; // XXX null should disable
109
// const DEFAULT_END = null; // disable end nodes display/input
@@ -32,24 +31,20 @@ const DIJK_EXAMPLE = 'Please provided positive numbers: 0,1'; //TODO
3231
const DIJK_EXAMPLE2 = 'Please enter the symmetrical value in matrix'; //TODO
3332
function DijkstraParam({ mode, xyCoords, edgeWeights, size, start, end, heuristic, min, max }) {
3433
const [message, setMessage] = useState(null);
35-
const graph_egs = [
36-
{ name: 'URL Input Graph',
37-
size: size || GRAPH_EGS[0].size,
38-
coords: xyCoords || GRAPH_EGS[0].coords,
39-
edges: edgeWeights || GRAPH_EGS[0].edges
40-
}
41-
]
34+
let [start1, size1, graph_egs] =
35+
addURLGraph(GRAPH_EGS, xyCoords, edgeWeights, start, DEFAULT_START);
36+
4237
return (
4338
<>
4439
{/* Matrix input */}
4540
<EuclideanMatrixParams
4641
name="dijkstra"
4742
mode="find"
48-
defaultSize={size || DEFAULT_SIZE}
49-
defaultStart={start || DEFAULT_START}
43+
defaultSize={ size1 }
44+
defaultStart={ start1 }
5045
defaultEnd={end || DEFAULT_END}
51-
defaultHeur = {heuristic || DEFAULT_HEUR}
52-
graphEgs={graph_egs || GRAPH_EGS}
46+
defaultHeur = {DEFAULT_HEUR}
47+
graphEgs={graph_egs}
5348
min={min || 1}
5449
max={max || 49}
5550
symmetric

src/algorithms/parameters/KRUSKALParam.js

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import React, { useState } from 'react';
33
import EuclideanMatrixParams from './helpers/EuclideanMatrixParams';
44
import '../../styles/Param.scss';
55
import PropTypes from 'prop-types'; // Import this for URL Param
6-
import { withAlgorithmParams } from './helpers/urlHelpers' // Import this for URL Param
6+
import { withAlgorithmParams, addURLGraph } from './helpers/urlHelpers'
77

88

99
const DEFAULT_SIZE = 5; // gets overwritten by GRAPH_EGS[0] now
@@ -34,23 +34,19 @@ const GRAPH_EGS = [ // XXX think up better examples?
3434

3535
function KRUSKALParam({ mode, xyCoords, edgeWeights, size, start, end, heuristic, min, max }) {
3636
const [message, setMessage] = useState(null);
37-
const graph_egs = [
38-
{ name: 'URL Input Graph',
39-
size: size || GRAPH_EGS[0].size,
40-
coords: xyCoords || GRAPH_EGS[0].coords,
41-
edges: edgeWeights || GRAPH_EGS[0].edges
42-
}
43-
]
37+
let [start1, size1, graph_egs] =
38+
addURLGraph(GRAPH_EGS, xyCoords, edgeWeights, start, DEFAULT_START);
39+
4440
return (
4541
<>
4642
{/* Matrix input */}
4743
<EuclideanMatrixParams
4844
name="kruskal"
4945
mode="find"
50-
defaultSize={size || DEFAULT_SIZE}
51-
defaultStart={start || DEFAULT_START}
46+
defaultSize={ size1 }
47+
defaultStart={ start1 }
5248
defaultEnd={end || DEFAULT_END}
53-
defaultHeur = {heuristic || DEFAULT_HEUR}
49+
defaultHeur = {DEFAULT_HEUR}
5450
// XXX
5551
// min&max for weights originally, then used for X&Y coordinates
5652
// as well (DOH!) (maybe avoid for weights in the future but
@@ -63,7 +59,7 @@ function KRUSKALParam({ mode, xyCoords, edgeWeights, size, start, end, heuristic
6359
min={min || 1}
6460
// max={9}
6561
max={max || 49}
66-
graphEgs={graph_egs || GRAPH_EGS}
62+
graphEgs={graph_egs}
6763
symmetric
6864
ALGORITHM_NAME={KRUSKAL}
6965
EXAMPLE={KRUSKAL_EXAMPLE}

src/algorithms/parameters/PRIMParam.js

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import React, { useState } from 'react';
33
import EuclideanMatrixParams from './helpers/EuclideanMatrixParams';
44
import '../../styles/Param.scss';
55
import PropTypes from 'prop-types'; // Import this for URL Param
6-
import { withAlgorithmParams } from './helpers/urlHelpers' // Import this for URL Param
6+
import { withAlgorithmParams, addURLGraph } from './helpers/urlHelpers'
77

88
const DEFAULT_SIZE = 5; // gets overwritten by GRAPH_EGS[0] now
99
const DEFAULT_START = 5; // XXX null should disable
@@ -33,23 +33,19 @@ const GRAPH_EGS = [ // XXX think up better examples?
3333

3434
function PRIMParam({ mode, xyCoords, edgeWeights, size, start, end, heuristic, min, max }) {
3535
const [message, setMessage] = useState(null);
36-
const graph_egs = [
37-
{ name: 'URL Input Graph',
38-
size: size || GRAPH_EGS[0].size,
39-
coords: xyCoords || GRAPH_EGS[0].coords,
40-
edges: edgeWeights || GRAPH_EGS[0].edges
41-
}
42-
]
36+
let [start1, size1, graph_egs] =
37+
addURLGraph(GRAPH_EGS, xyCoords, edgeWeights, start, DEFAULT_START);
38+
4339
return (
4440
<>
4541
{/* Matrix input */}
4642
<EuclideanMatrixParams
4743
name="prim"
4844
mode="find"
49-
defaultSize={size || DEFAULT_SIZE}
50-
defaultStart={start || DEFAULT_START}
45+
defaultSize={ size1 }
46+
defaultStart={ start1 }
5147
defaultEnd={end || DEFAULT_END}
52-
defaultHeur = {heuristic || DEFAULT_HEUR}
48+
defaultHeur = {DEFAULT_HEUR}
5349
// XXX
5450
// min&max for weights originally, then used for X&Y coordinates
5551
// as well (DOH!) (maybe avoid for weights in the future but
@@ -62,7 +58,7 @@ function PRIMParam({ mode, xyCoords, edgeWeights, size, start, end, heuristic, m
6258
min={min || 1}
6359
// max={9}
6460
max={max || 49}
65-
graphEgs={graph_egs || GRAPH_EGS}
61+
graphEgs={graph_egs}
6662
symmetric
6763
ALGORITHM_NAME={PRIMS}
6864
EXAMPLE={PRIMS_EXAMPLE}

src/algorithms/parameters/TCParam.js

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@ import React, { useState } from 'react';
44
import EuclideanMatrixParams from './helpers/EuclideanMatrixParams';
55
import '../../styles/Param.scss';
66
import PropTypes from 'prop-types'; // Import this for URL Param
7-
import { withAlgorithmParams } from './helpers/urlHelpers' // Import this for URL Param
7+
import { withAlgorithmParams, addURLGraph } from './helpers/urlHelpers'
8+
89

910
const DEFAULT_SIZE = 4; // gets overwritten by GRAPH_EGS[0] now
1011
const DEFAULT_START = null; // disable
@@ -30,23 +31,25 @@ const GRAPH_EGS = [ // XXX think up better examples?
3031
edges: '1-2,2-1,2-3,3-4,4-5,5-3'
3132
}];
3233

33-
function TransitiveClosureParam({ mode, size, min, max}) {
34+
function TransitiveClosureParam({ mode, xyCoords, edgeWeights, size, start, end, heuristic, min, max }) {
3435
const [message, setMessage] = useState(null);
36+
let [start1, size1, graph_egs] =
37+
addURLGraph(GRAPH_EGS, xyCoords, edgeWeights, start, DEFAULT_START);
3538

3639
return (
3740
<>
3841
{/* Matrix input */}
3942
<EuclideanMatrixParams
4043
name="transitiveClosure"
4144
mode="tc"
42-
defaultSize={size || DEFAULT_SIZE}
43-
defaultStart={DEFAULT_START}
45+
defaultSize={ size1 }
46+
defaultStart={ start1 }
4447
defaultEnd={DEFAULT_END}
4548
defaultWeight = {DEFAULT_WEIGHT}
4649
defaultHeur = {DEFAULT_HEUR}
4750
min={min || 1}
4851
max={max || 49}
49-
graphEgs={GRAPH_EGS}
52+
graphEgs={ graph_egs }
5053
ALGORITHM_NAME={TRANSITIVE_CLOSURE}
5154
EXAMPLE={TRANSITIVE_CLOSURE_EXAMPLE}
5255
setMessage={setMessage}
@@ -66,6 +69,11 @@ TransitiveClosureParam.propTypes = {
6669
alg: PropTypes.string.isRequired,
6770
mode: PropTypes.string.isRequired,
6871
size: PropTypes.string.isRequired,
72+
start: PropTypes.string.isRequired,
73+
end: PropTypes.string.isRequired,
74+
heuristic: PropTypes.string.isRequired,
75+
xyCoords: PropTypes.string.isRequired,
76+
edgeWeights: PropTypes.string.isRequired,
6977
min: PropTypes.string.isRequired,
7078
max: PropTypes.string.isRequired,
7179
};

0 commit comments

Comments
 (0)