Skip to content

Commit 8c4be63

Browse files
authored
Merge branch '2024_sem2' into khai/progressbar
2 parents 6717b48 + 241baa6 commit 8c4be63

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

46 files changed

+19456
-18907
lines changed

.idea/.name

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/workspace.xml

Lines changed: 40 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
31.7 KB
Binary file not shown.

package-lock.json

Lines changed: 17236 additions & 18314 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -66,13 +66,13 @@
6666
"denque": "^2.0.1",
6767
"framer-motion": "^4.0.0",
6868
"lodash": "^4.17.21",
69-
"prop-types": "^15.7.2",
69+
"prop-types": "^15.8.1",
7070
"react": "^17.0.2",
7171
"react-dom": "^17.0.2",
7272
"react-markdown": "^5.0.0",
7373
"react-resize-detector": "^6.6.0",
7474
"react-router-dom": "^5.2.0",
75-
"react-scripts": "^4.0",
75+
"react-scripts": "^5.0.1",
7676
"react-table": "^7.5.0",
7777
"reactjs-popup": "^2.0.5",
7878
"remark-gfm": "^1.0.0",
@@ -83,7 +83,7 @@
8383
},
8484
"devDependencies": {
8585
"@babel/plugin-proposal-private-property-in-object": "^7.21.11",
86-
"electron": "^15.0.0",
86+
"electron": "^31.4.0",
8787
"enzyme": "^3.11.0",
8888
"eslint": "^7.11.0",
8989
"eslint-plugin-import": "^2.28.1",
@@ -96,4 +96,3 @@
9696
"run-script-os": "^1.1.6"
9797
}
9898
}
99-

src/algorithms/controllers/TTFTreeInsertion.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -347,6 +347,7 @@ export default {
347347
},
348348

349349
run(chunker, { nodes }) {
350+
350351
if (nodes === null || nodes.length === 0) return;
351352
let { node: tree, id: newID } = this.createNodeAndIncrement(null);
352353

src/algorithms/controllers/sorts.c

Lines changed: 92 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,9 @@
77
// #define QUICKSORT // some version of quicksort
88
// #define MERGE_TD // top-down merge sort
99
// #define MERGE_BUP // bottom-up merge sort
10+
#define MERGE_NAT // natural merge sort
1011
// #define MSD_RADIX // radix exchange sort
11-
#define MERGE_TD_LA // top-down merge sort for lists imp as arrays
12+
// #define MERGE_TD_LA // top-down merge sort for lists imp as arrays
1213
// XXX should do top-down merge sort for lists imp with pointers - main code
1314
// should be identical - just need to write init code for list and change
1415
// some macro definitions
@@ -59,6 +60,10 @@ List mergesort_td_la(int L, int len);
5960
void mergesort_bup(int A[], int size);
6061
#endif // MERGE_BUP
6162

63+
#ifdef MERGE_NAT
64+
void mergesort_nat(int A[], int size);
65+
#endif // MERGE_NAT
66+
6267
#ifdef MSD_RADIX
6368
int radix_partition(int *A, int left, int right, int mask);
6469
void msd_radix_sort(int A[], int left, int right, int mask);
@@ -102,6 +107,9 @@ main() {
102107
#ifdef MERGE_BUP
103108
mergesort_bup(A, Size-1);
104109
#endif // MERGE_BUP
110+
#ifdef MERGE_NAT
111+
mergesort_nat(A, Size-1);
112+
#endif // MERGE_NAT
105113
for (i=1; i < Size; i++) printf("%d ", A[i]); printf("\n");
106114
}
107115

@@ -323,7 +331,7 @@ mergesort_td(int A[], int left, int right) {
323331
List
324332
mergesort_td_la(int L, int len) {
325333
int i, mid;
326-
List Lmid, R, M, E;
334+
List Lmid, R, M, Mlast;
327335

328336
if (len > 1) {
329337
// determine Lmid, the mid point of L
@@ -362,23 +370,23 @@ mergesort_td_la(int L, int len) {
362370
R = tail(R);
363371
}
364372
// scan through adding elements to the end of M
365-
E = M;
373+
Mlast = M;
366374
while (L != Null && R != Null) {
367375
if (head(L) <= head(R)) {
368-
tail(E) = L;
369-
E = L;
376+
tail(Mlast) = L;
377+
Mlast = L;
370378
L = tail(L);
371379
} else {
372-
tail(E) = R;
373-
E = R;
380+
tail(Mlast) = R;
381+
Mlast = R;
374382
R = tail(R);
375383
}
376384
}
377385
// add any elements not scanned to the end of M
378386
if (L == Null)
379-
tail(E) = R;
387+
tail(Mlast) = R;
380388
else
381-
tail(E) = L;
389+
tail(Mlast) = L;
382390
printf("Merged: ");
383391
for (Lmid = M; Lmid != Null; Lmid = tail(Lmid))
384392
printf(" %d", head(Lmid));
@@ -397,7 +405,7 @@ mergesort_td_la(int L, int len) {
397405
#endif // MERGE_TD_LA
398406

399407
#ifdef MERGE_BUP
400-
// XXX could reduce duplication with MERGE_TD
408+
// XXX could reduce duplication with MERGE_TD and MERGE_NAT
401409
int B[Size];
402410

403411
int
@@ -460,3 +468,77 @@ printf("Merging %d %d %d - %d\n", left, mid, right, runlength);
460468
}
461469

462470
#endif // MERGE_BUP
471+
472+
#ifdef MERGE_NAT
473+
// XXX could reduce duplication with MERGE_TD and MERGE_BUP
474+
int B[Size];
475+
476+
int
477+
minimum(int i, int j) {
478+
if (i <= j)
479+
return i;
480+
else
481+
return j;
482+
}
483+
484+
// Sort array A[1]..A[size] in ascending order
485+
void
486+
mergesort_nat(int A[], int size) {
487+
int runcount, left, mid, right;
488+
int ap1, ap1max, ap2, ap2max, bp;
489+
490+
do {
491+
runcount = 0;
492+
left = 1;
493+
do {
494+
// find the first run, A[left..mid]
495+
mid = left;
496+
while (mid < size && A[mid] <= A[mid+1])
497+
mid++;
498+
// find the second run, A[mid+1..right]
499+
right = mid+1;
500+
while (right < size && A[right] <= A[right+1])
501+
right++;
502+
if (mid < size) {
503+
// merge A[left..mid] and A[mid+1..right], with the result in A
504+
printf("Merging %d %d %d \n", left, mid, right);
505+
ap1 = left;
506+
ap1max = mid;
507+
ap2 = mid+1;
508+
ap2max = right;
509+
bp = left;
510+
while (ap1 <= ap1max && ap2 <= ap2max)
511+
if (A[ap1] < A[ap2]) {
512+
B[bp] = A[ap1];
513+
ap1 = ap1+1;
514+
bp = bp+1;
515+
} else {
516+
B[bp] = A[ap2];
517+
ap2 = ap2+1;
518+
bp = bp+1;
519+
}
520+
while (ap1 <= ap1max) {
521+
B[bp] = A[ap1];
522+
ap1 = ap1+1;
523+
bp = bp+1;
524+
}
525+
while (ap2 <= ap2max) {
526+
B[bp] = A[ap2];
527+
ap2 = ap2+1;
528+
bp = bp+1;
529+
}
530+
for (bp = left; bp <= right; bp++)
531+
A[bp] = B[bp];
532+
}
533+
runcount++;
534+
left = right + 1;
535+
} while (left < size);
536+
} while (runcount > 1);
537+
// if (left < right-1) { // for testing/debugging
538+
// int i1;
539+
// printf("Ret from ms(%d, %d): ", left, right);
540+
// for (i1=1; i1 < Size; i1++) printf("%d ", A[i1]); printf("\n");
541+
// }
542+
}
543+
544+
#endif // MERGE_NAT

src/algorithms/controllers/transitiveClosure.js

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@ export default {
1919
initVisualisers() {
2020
return {
2121
graph: {
22-
instance: new GraphTracer('key', null, 'Transitive Closure'),
22+
// instance: new GraphTracer('key', null, 'Transitive Closure'),
23+
instance: new GraphTracer('key', null, 'Graph view'),
2324
order: 0
2425
},
2526
// create a separate component for displaying the matrix as a 2D array
@@ -42,22 +43,25 @@ export default {
4243
return out;
4344
},
4445

45-
run(chunker, { matrix, size }) {
46+
run(chunker, { edgeValueMatrix, coordsMatrix, startNode, endNodes, moveNode}) {
4647
// eslint-disable-next-line no-unused-expressions
48+
const matrix = edgeValueMatrix;
49+
const size = matrix.length;
4750
const numOfNodes = size;
4851
const nodes = new Array(numOfNodes);
4952
let prevI = 0;
5053
let prevJ = 0;
5154
let prevK = 0;
52-
chunker.add(1, (g) => {
55+
chunker.add(1, (g, edgeArray, coordsArray) => {
5356
// show kth tag when step back
5457
setKthVisible(true);
5558
g.array.set([...matrix], 'tc');
56-
g.graph.set([...matrix], Array.from({ length: matrix.length }, (v, k) => (k + 1)));
57-
g.graph.layoutCircle();
59+
g.graph.set(edgeArray, Array.from({ length: matrix.length }, (v, k) => (k + 1)),coordsArray);
60+
// g.graph.layoutCircle();
5861
// initialise the matrix in the 'Matrix' component
5962
g.graph.setIstc();
60-
}, [this.graph], [this.array]);
63+
g.graph.moveNodeFn(moveNode);
64+
}, [[...edgeValueMatrix], [...coordsMatrix]]);
6165

6266
for (let i = 0; i < numOfNodes; i++) {
6367
nodes[i] = this.copyArr([...matrix]);

src/algorithms/index.js

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,6 @@ import * as Instructions from './instructions';
2222
src/context/actions.js had better be deployed!
2323
XXX Design of noDeploy stuff was done with the aim of minimal code change
2424
and could be re-thought when there are fewer merges going on.
25-
XXX we could export and use allalgs in key places in the system,
26-
eg src/context/actions.js so we can still access them via the URL, but
27-
not have them appear in the index.
2825
2926
Each imported algorithm is expected to be an object of the form:
3027
{ pseudocode: String, explanation: String, run: Function }
@@ -182,7 +179,6 @@ const allalgs = {
182179
},
183180
},
184181
'BFS': {
185-
186182
name: 'Breadth First Search',
187183
category: 'Graph',
188184
param: <Param.BFSParam/>,
@@ -351,7 +347,13 @@ const algorithms =
351347
* Get the first mode of an algorithm
352348
* @param {string} key algorithm's name
353349
*/
354-
const getDefaultMode = (key) => Object.keys(algorithms[key].pseudocode)[0];
350+
export const getDefaultMode = (key) => Object.keys(algorithms[key].pseudocode)[0];
351+
352+
/**
353+
* Get the category of an algorithm
354+
* @param {string} key algorithm's name
355+
*/
356+
export const getCategory = (key) => algorithms[key].category;
355357

356358
// This function generates a list of algorithms classed by categories
357359
const generateAlgorithmCategoryList = () => {

src/algorithms/parameters/ASTParam.js

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

79
// Note: 'A* Algorithm' currently used in EuclideanMatrixParams.js -
810
// change both or neither!
@@ -30,23 +32,30 @@ const GRAPH_EGS = [ // XXX think up better examples?
3032
edges:
3133
'1-2-10,1-4-4,2-3-6,3-4-10,3-5-5,4-7-3,5-6-7,6-7-8,7-8-2,7-9,8-9-3,9-10-5,9-11-7, 10-11-7,11-13-4,12-13-8,12-14-6,13-14-7,13-15-7,14-16-6,15-16-2,15-17-5,16-17-2'
3234
}];
33-
function ASTParam() {
35+
function ASTParam( { mode, xyCoords, edgeWeights, size, start, end, heuristic, min, max } ) {
3436
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+
]
3544

3645
return (
3746
<>
3847
{/* Matrix input */}
3948
<EuclideanMatrixParams
4049
name="aStar"
4150
mode="find"
42-
defaultSize={DEFAULT_SIZE}
43-
defaultStart={DEFAULT_START}
44-
defaultEnd={DEFAULT_END}
45-
heuristic = {DEFAULT_HEUR}
46-
min={1}
47-
max={49}
51+
defaultSize={ size || DEFAULT_SIZE }
52+
defaultStart={ start || DEFAULT_START }
53+
defaultEnd={ end || DEFAULT_END }
54+
heuristic = { heuristic || DEFAULT_HEUR }
55+
min={ min || 1 }
56+
max={ max || 49 }
4857
symmetric
49-
graphEgs={GRAPH_EGS}
58+
graphEgs={ graph_egs || GRAPH_EGS }
5059
ALGORITHM_NAME={ASTAR}
5160
EXAMPLE={ASTAR_EXAMPLE}
5261
EXAMPLE2={ASTAR_EXAMPLE2}
@@ -60,4 +69,32 @@ function ASTParam() {
6069
);
6170
}
6271

63-
export default ASTParam;
72+
// Define the prop types for URL Params
73+
ASTParam.propTypes = {
74+
alg: PropTypes.string.isRequired,
75+
mode: PropTypes.string.isRequired,
76+
size: PropTypes.string.isRequired,
77+
start: PropTypes.string.isRequired,
78+
end: PropTypes.string.isRequired,
79+
heuristic: PropTypes.string.isRequired,
80+
xyCoords: PropTypes.string.isRequired,
81+
edgeWeights: PropTypes.string.isRequired,
82+
min: PropTypes.string.isRequired,
83+
max: PropTypes.string.isRequired,
84+
};
85+
// ASTParam.propTypes = {
86+
// alg: PropTypes.string.isRequired,
87+
// mode: PropTypes.string.isRequired,
88+
// size: PropTypes.number.isRequired,
89+
// start: PropTypes.arrayOf(PropTypes.number),
90+
// end: PropTypes.arrayOf(PropTypes.number),
91+
// heuristic: PropTypes.number.isRequired,
92+
// xyCoords: PropTypes.string,
93+
// edgeWeights: PropTypes.string,
94+
// min: PropTypes.number,
95+
// max: PropTypes.number
96+
// };
97+
98+
export default withAlgorithmParams(ASTParam); // Export with the wrapper for URL Params
99+
100+

0 commit comments

Comments
 (0)