diff --git a/OCaml-toposortlab/Dockerfile b/OCaml-toposortlab/Dockerfile new file mode 100644 index 0000000..9aa4220 --- /dev/null +++ b/OCaml-toposortlab/Dockerfile @@ -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 \ No newline at end of file diff --git a/OCaml-toposortlab/README.md b/OCaml-toposortlab/README.md new file mode 100644 index 0000000..cc34692 --- /dev/null +++ b/OCaml-toposortlab/README.md @@ -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 +``` diff --git a/OCaml-toposortlab/autograde-Makefile b/OCaml-toposortlab/autograde-Makefile new file mode 100644 index 0000000..9837016 --- /dev/null +++ b/OCaml-toposortlab/autograde-Makefile @@ -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 \ No newline at end of file diff --git a/OCaml-toposortlab/autograde.tar b/OCaml-toposortlab/autograde.tar new file mode 100644 index 0000000..56ae619 Binary files /dev/null and b/OCaml-toposortlab/autograde.tar differ diff --git a/OCaml-toposortlab/toposort.ml b/OCaml-toposortlab/toposort.ml new file mode 100644 index 0000000..3e4e2a1 --- /dev/null +++ b/OCaml-toposortlab/toposort.ml @@ -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