-
Notifications
You must be signed in to change notification settings - Fork 5
Added an OCaml autograder #18
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
anthony-yip
wants to merge
1
commit into
main
Choose a base branch
from
anthony-yip-patch-1
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
FROM ocaml/opam:ubuntu-20.04-ocaml-4.10 | ||
|
||
RUN opam install base yojson | ||
RUN eval $(opam env) | ||
USER root | ||
|
||
|
||
# Install autodriver | ||
WORKDIR /home | ||
RUN useradd autolab | ||
RUN useradd autograde | ||
RUN mkdir autolab autograde output | ||
RUN chown autolab:autolab autolab | ||
RUN chown autolab:autolab output | ||
RUN chown autograde:autograde autograde | ||
RUN git clone https://github.com/autolab/Tango.git | ||
WORKDIR Tango/autodriver | ||
RUN make clean && make | ||
RUN cp autodriver /usr/bin/autodriver | ||
RUN chmod +s /usr/bin/autodriver | ||
|
||
# Clean up | ||
WORKDIR /home | ||
RUN apt-get remove -y git | ||
RUN apt-get -y autoremove | ||
RUN rm -rf Tango/ | ||
|
||
# Check installation | ||
RUN ls -l /home | ||
RUN which autodriver |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
# OCaml-toposortlab | ||
|
||
### Assessment Language | ||
OCaml | ||
|
||
### Autograder Language | ||
OCaml | ||
|
||
|
||
### Autograding Environment Packages | ||
The following opam packages: | ||
- yojson | ||
- base | ||
|
||
A Dockerfile is provided to install the necessary packages. | ||
### Assessment Scenario | ||
Students are required to implement a topological sort function in OCaml matching a graph interface. | ||
|
||
### Handin Format | ||
Single file called toposort.ml | ||
|
||
### autograder.tar Directory Content | ||
The standard directories in a Dune project: | ||
``` | ||
bin/ | ||
lib/ | ||
test/ | ||
dune-project | ||
``` |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
all: copy | ||
|
||
copy: | ||
tar -xvf autograde.tar | ||
cp toposort.ml toposortlab_dune/lib | ||
cd toposortlab_dune && \ | ||
dune build && \ | ||
dune test | ||
|
||
clean: | ||
rm -r toposortlab_dune |
Binary file not shown.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
open Core | ||
|
||
type graph = { | ||
nodes : int list; | ||
edges : (int * int) list; | ||
} | ||
|
||
let topological_sort (g : graph) : int list = | ||
let visited = Hash_set.create (module Int) in | ||
(* Construct the adjacency list representation of the graph*) | ||
let adj_list = Int.Map.of_alist_multi g.edges in | ||
let rec dfs_helper (acc : int list) (node : int) = | ||
if Hash_set.mem visited node then | ||
acc | ||
else | ||
let () = Hash_set.add visited node in | ||
let neighbors = (match Int.Map.find adj_list node with | ||
| Some neighbors -> neighbors | ||
| None -> []) in | ||
let acc = List.fold ~init:acc ~f:(dfs_helper) neighbors in | ||
node :: acc | ||
in | ||
List.fold ~init:[] ~f:(dfs_helper) g.nodes | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Topological sort algorithm has an issue with cycle detection
The topological sort implementation works well for DAGs (Directed Acyclic Graphs), but doesn't handle cycles correctly. In the presence of cycles, the algorithm will still produce output but it won't be a valid topological sorting.
Consider adding cycle detection:
📝 Committable suggestion