diff --git a/README.md b/README.md index 536c884..50969fd 100644 --- a/README.md +++ b/README.md @@ -1,8 +1,9 @@ This project contains some basic UNIX command line tools I had to do for TU. Currently the toolset is ther following: -* mygrep - a simplified version of grep -* http - an implementation of HTTP 1.1 client and server -* cpair - a program that searches for the closest pair of points in a set of 2D-points +* (mygrep)[mygrep] - a simplified version of grep +* (http)[http] - an implementation of HTTP 1.1 client and server +* (cpair)[cpair] - a program that searches for the closest pair of points in a set of 2D-points +* (fb_arc_set)[fb_arc_set] - a set of programs that removes cycles in a directed graph Feel free to read the descriptions for each tool. \ No newline at end of file diff --git a/fb_arc_set/Makefile b/fb_arc_set/Makefile new file mode 100644 index 0000000..1624de4 --- /dev/null +++ b/fb_arc_set/Makefile @@ -0,0 +1,30 @@ +CC = gcc +CFLAGS = -std=c99 -pedantic -Wall -D_DEFAULT_SOURCE -D_BSD_SOURCE -D_SVID_SOURCE -D_POSIX_C_SOURCE=200809L -g -c +TARGET_1 = generator +TARGET_2 = supervisor + +all: $(TARGET_1).c $(TARGET_2).c + $(CC) $(CFLAGS) $(TARGET_1).c $(TARGET_2).c + $(CC) $(TARGET_1).o -o $(TARGET_1) + $(CC) $(TARGET_2).o -o $(TARGET_2) + +generator: $(TARGET_1).c + $(CC) $(CFLAGS) $(TARGET_1).c + $(CC) $(TARGET_1).o -o $(TARGET_1) + +supervisor: $(TARGET_2).c + $(CC) $(CFLAGS) $(TARGET_2).c + $(CC) $(TARGET_2).o -o $(TARGET_2) + +install: + cp $(TARGET_1) /usr/local/bin/graph-$(TARGET_1) + cp $(TARGET_2) /usr/local/bin/graph-$(TARGET_2) + +clean: + $(RM) $(TARGET_1) + $(RM) $(TARGET_2) + $(RM) *.o + $(RM) *.tgz + +package: + tar -cvzf fb_arc_set.tgz $(TARGET_1).c $(TARGET_2).c Makefile diff --git a/fb_arc_set/README.md b/fb_arc_set/README.md new file mode 100644 index 0000000..68f51ba --- /dev/null +++ b/fb_arc_set/README.md @@ -0,0 +1,34 @@ +# fb_arc_set +The aim of these 2 modules is to implement an algorithm which removes cycles in a directed graph by removing the least edges possible. +A set of edges which must be removed to make a graph acyclic is also called a feedback arc set; and the +set with the least edges is a minimal feedback arc set. + +## Algorithm + +A simple randomized algorithm for this problem generates a feedback arc set by executing following steps: +* Order the vertices of the graph randomly, i.e. generate a random permutation of the set of vertices. +* Select all edges ( u, v ) for which u > v in the ordering. These edges form a feedback arc set. + +## generator + +The generator program takes a graph as input. The program repeatedly generates a random solution +to the problem as described above and writes its result to a circular buffer. It repeats this procedure until it is notified by the supervisor to terminate. + + SYNOPSIS + generator EDGE1... + EXAMPLE + generator 0-1 1-2 1-3 1-4 2-4 3-6 4-3 4-5 6-0 + +## supervisor + +The supervisor sets up the shared memory and the semaphores and initializes the circular buffer required +for the communication with the generators. It then waits for the generators to write solutions to the +circular buffer. +The supervisor program takes no arguments. +Once initialization is complete, the supervisor reads the solutions from the circular buffer and remem- +bers the best solution so far, i.e. the solution with the least edges. Every time a better solution than the previous best solution is found, the supervisor writes the new solution to standard output. If a generator writes a solution with 0 edges to the circular buffer, then the graph is acyclic and the supervisor terminates. Otherwise the supervisor keeps reading results from the circular buffer until it receives a `SIGINT` or a `SIGTERM` signal. +Before terminating, the supervisor notifies all generators that they should terminate as well. This can +be done by setting a variable in the shared memory, which is checked by the generator processes before +writing to the buffer. The supervisor then unlinks all shared resources and exits + +**Note: The description is from the task I got from TU.** \ No newline at end of file diff --git a/fb_arc_set/generator.c b/fb_arc_set/generator.c new file mode 100644 index 0000000..e69de29 diff --git a/fb_arc_set/supervisor.c b/fb_arc_set/supervisor.c new file mode 100644 index 0000000..e69de29