C++ P threads program

profilekmuitiriri
2005366_1626827556_8996-53bonus-ttest-file.zip

bonus ttest file/Assignm3.h

#ifndef Assignm3_H #define Assignm3_H // ------------------------------------------------------------------------------------ #include <vector> #include <string> #include <pthread.h> #include "Path.h" #include "Maze.h" #include "ProgramLog.h" #include "Assignm3_Utils.h" #include "SubmitMazeSoln.h" // ------------------------------------------------------------------------------------ namespace Assignm3 { const int MAX_NO_OF_THREADS = 3; const std::string THREAD_NAMES [] = {"POOH", "TIGGER", "ROO", "GOLPHER", "KANGA", "LUMPY", "OWL", "RABBIT", "PIGLET", "POOH0", "TIGGER0", "ROO0", "GOLPHER0", "KANGA0", "LUMPY0", "OWL0", "RABBIT0", "PIGLET0", "POOH1", "TIGGER1", "ROO1", "GOLPHER1", "KANGA1", "LUMPY1", "OWL1", "RABBIT1", "PIGLET1", "POOH2", "TIGGER2", "ROO2", "GOLPHER2", "KANGA2", "LUMPY2", "OWL2", "RABBIT2", "PIGLET2", "POOH3", "TIGGER3", "ROO3", "GOLPHER3", "KANGA3", "LUMPY3", "OWL3", "RABBIT3", "PIGLET3", "POOH4", "TIGGER4", "ROO4", "GOLPHER4", "KANGA4", "LUMPY4", "OWL4", "RABBIT4", "PIGLET4", "POOH5", "TIGGER5", "ROO5", "GOLPHER5", "KANGA5", "LUMPY5", "OWL5", "RABBIT5", "PIGLET5" }; // ------------------------------------------------------------------------------------ // ------------------------------------------------------------------------------------ // ------------------------------------------------------------------------------------ struct PathFinderParameterInfo { int threadIDArrayIndex; bool exitThisThreadNow; Point currentLocation; std::string threadName; VectorOfPointStructType travelledPath; PathFinderParameterInfo (void) { currentLocation.x = -1; currentLocation.y = -1; threadIDArrayIndex = -1; exitThisThreadNow = false; travelledPath = VectorOfPointStructType (); } ~PathFinderParameterInfo (void) { travelledPath.clear (); } }; // ------------------------------------------------------------------------------------ struct PathFinderResource { pthread_t activeThreadArray [MAX_NO_OF_THREADS]; PathFinderParameterInfo * activeThreadParamArray [MAX_NO_OF_THREADS]; VectorOfPointStructType solutionPath; VectorOfPointStructType discoveredDangerAreas; int usedThreadNameIndex; int noOfDeadEndPathsFound; int noOfBarriersDiscovered; int noOfDangerAreaDiscovered; PathFinderResource (void) { usedThreadNameIndex = 0; noOfDeadEndPathsFound = 0; noOfBarriersDiscovered = 0; noOfDangerAreaDiscovered = 0; solutionPath = VectorOfPointStructType (); discoveredDangerAreas = VectorOfPointStructType (); } ~PathFinderResource (void) { solutionPath.clear (); discoveredDangerAreas.clear (); } }; PathFinderResource globalPathFinderResource; // ------------------------------------------------------------------------------------ static Maze * mazeObj; static Path * pathObj; static SubmitMazeSoln * submitMazeSolnObj; static std::fstream logFileStream; static std::string DefaultLogFilename = "Assignm3Log.txt"; static pthread_mutex_t thread_mutex = PTHREAD_MUTEX_INITIALIZER; static pthread_cond_t thread_condition = PTHREAD_COND_INITIALIZER; static bool mainThreadReportUpdateNow = false; static bool discoveredASolutionPath = false; // ------------------------------------------------------------------------------------ static void AllocateProgramsVariableMemory (void) { mazeObj = new Maze (); pathObj = new Path (); submitMazeSolnObj = new SubmitMazeSoln (); logFileStream.open (DefaultLogFilename.c_str(), std::fstream::out); } // end allocateProgramsVariableMemory () ... // ------------------------------------------------------------------------------------ static void DeallocateProgramsVariableMemory (void) { delete mazeObj; delete pathObj; delete submitMazeSolnObj; logFileStream.close (); pthread_mutex_destroy ( &thread_mutex ); pthread_cond_destroy ( &thread_condition ); } // end deallocateProgramsVariableMemory () ... // ------------------------------------------------------------------------------------ static void HandleThreadOperationResult (std::ostream & outputStream, const std::string message, const int status) { if (status) { std::string msg = "Error on : " + message + ", ERROR CODE = " + IntToString (status) + "\n"; // below function 'WriteLogMessage' is defined in 'ProgramLog.h' ... WriteLogMessage (std::cout, msg); WriteLogMessage (outputStream, msg); DeallocateProgramsVariableMemory (); exit (EXIT_FAILURE); } } // end handleThreadOperationResult () ... // ------------------------------------------------------------------------------------ // ------------------------------------------------------------------------------------ } // end namespace Assignm3 #endif // Assignm3_H

bonus ttest file/Assignm3_Utils.h

#ifndef Assignm3_UTILS_H #define Assignm3_UTILS_H #include <vector> #include <string> #include <iostream> // cout, endl #include <sstream> // ostringstream #include <cstdlib> // srand, rand // ------------------------------------------------------------------------------------ struct Point { int x; int y; Point () { x = NULL; y = NULL; } Point (int x1, int y1) { x = x1; y = y1; } ~Point (void) { } Point & operator= (const Point &p) { x = p.x; y = p.y; return (*this); } bool operator== (const Point &p) { return ( (x == p.x) && (y == p.y) ); } bool operator!= (const Point &p) { return ( (x != p.x) || (y != p.y) ); } // 2 points are 'connected' but 'different' if they : // i) share the same 'x' but adjacent 'y' values, OR // ii) share the same 'y' but adjacent 'x' values!! bool isConnected (Point &p) { return ( ((x == p.x) && ( ((y-1) == p.y) || ((y+1) == p.y) )) || ((y == p.y) && ( ((x-1) == p.x) || ((x+1) == p.x) )) ); } void display (std::ostream &outputStream=std::cout) { outputStream << "[" << x << ", " << y << "]"; } }; // ------------------------------------------------------------------------------------ // type define a vector of Point structs ... typedef std::vector<Point> VectorOfPointStructType; // type define a vector of VectorOfPointStructType ... typedef std::vector<VectorOfPointStructType> VectorOfVectorOfPointStructType; // ------------------------------------------------------------------------------------ static std::string IntToString (const int intValue) { std::ostringstream oss (std::ostringstream::out); oss << intValue; return ( oss.str() ); } // end intToString () ... // ------------------------------------------------------------------------------------ static int GenerateRandomInteger (const int lowerLimit, const int upperLimit) { time_t secs; time (&secs); std::srand ( (unsigned int) secs ); return ( std::rand () % (upperLimit - lowerLimit + 1) + lowerLimit ); } // end GenerateRandomInteger () ... // ------------------------------------------------------------------------------------ #endif // Assignm3_UTILS_H

bonus ttest file/Assn3 Notes.txt

Assignment 3 ============= Impt Note 1 : ============= 1) You are given files like Maze.o and Maze.h which helps to process maze info from mazedata.txt file! 2) Your job is simply to study the *.h files, and experiment with how to invoke the useful methods encapsulated within! 3) You are to create a "global resource" data structure representing Maze that your threads should explore 4) This data structure represents the "knowledge", your threads have gathered : a) The coordinates of the barriers b) The coordinates of the danger areas c) The 'Start' and 'End' coordinates 5) In the BEGINNING, this data structure should ONLY have : a) The 'Start' and 'End' coordinates b) The size of the maze (to specify the size of your 2D array) 6) At the END, this data structure should contain : a) ONE solution : which is a valid PATH from 'Start' to 'End' b) The coordinates of all barriers and danger areas encountered, in the course of discovering the valid PATH 7) Do not "short-cut", by reading in from mazedata.txt, and presenting that as your output ans! (It is v. easy for me to discover whether you are using a genuine, multi-thread program or not) ============= Impt Note 2 : ============= 1) Your final program MUST compile together with SubmitMazeSoln.o !! 2) Your final program MUST call the methods in SubmitMazeSoln.o to submit your soln !! 3) Your final program MUST display graphically your final solution 4) Your final program MUST show the no. of steps taken from S to E (Start to End) 5) Advantage : When you make use of the methods in SubmitMazeSoln, a lot of output required in the Assignment would have been taken care of for you! To compile: g++ -c yourprogram.cpp g++ Maze.o Path.o SubmitMazeSoln.o yourprogram.o -o myexplorer.exe ============= Impt Note 3 : ============= Students are NOT supposed to modify anything in the header (*.h) files given to you. All changes must be made in your own program files!

bonus ttest file/CSCI212_Assignmt3 (1).doc

University of Wollongong

School of Computing and Information Technology

CSCI212 Interacting Systems

Assignment 3

Aim

The objective of this assignment is to apply the concepts of threading by developing a simple C++ Pthreads program to discover the surroundings and the shortest path in a 2D maze

Background

This assignment requires you to write a multi-threaded C/C++ “Pathfinder” program to discover the surroundings of a jungle maze. Each [x, y] location in the maze represents a ‘grid area’ of the jungle terrain. A particular gird area could be :

· “impassable” (rep. by ‘#’ barrier) ,

· contains danger (rep. by ‘X’ danger area)

· clear, (i.e. allows you to travel)

An example of the jungle maze will be provided to you (see Appendix A, ‘mazedata.txt’).

Your objective is to explore as much of the jungle maze terrain as possible, and mark the discovered area as barrier (‘#’), or danger (‘X’) accordingly.

When your program terminate, it should output a map of the explored jungle maze, as well as 1 ‘safe’ path, to traverse from Start to End locations.

Task Requirements

A) At startup, your program should read in the 2D maze configuration (“mazedata.txt”) which stores the information about the maze dimensions, barriers, start and end locations. Please refer to Appendix A for an example.

B) For the purposes of testing your program, a sample of what information should be output is shown in Appendix B.

C) Before you start developing your program, you should take some time to review the output, and analyze the requirements of the Pathfinder program.

D) Your program should have at least 2 threads, each thread attempting to explore surrounding locations to discover whether it contains a barrier (‘#’) or danger (‘X’).

E) Impt 1 : your program should maintain a global Maze resource or variable, holding information about all the barriers or danger areas uncovered by your exploring threads!

F) Impt 2 : when a particular thread has encountered a barrier (‘#’) or danger (‘X’), it should …

· Record the path (history of point locations) it has traversed, since the Start Location, to reach the barrier / danger areas, and locations of barrier / danger should be marked on your ‘global Maze resource’

· The thread ‘loses its life’ (i.e. should be destroyed) if it has encountered a danger area (‘X’) !!

G) Whenever a thread is destroyed, your program should create another replacement thread, to traverse the jungle maze beginning from the Start Location again. But this time, it should access the ‘global Maze resource’ to learn and avoid the barriers and danger areas discovered by its predecessor threads!

H) In this way, the ‘sacrifice’ of the destroyed threads are not in vain, as its knowledge (of locations of the barriers / danger areas) have been recorded in the ‘global Maze resource’ that can be accessed by future generations of created threads to aid their survival in order to discover a path to End Location!

I) As you probably guess by now, the access to the ‘global Maze resource’ should be protected via usage of mutex locks. Whether a thread is:

· Updating its discovery of the path to barrier / danger areas OR

· Accessing the ‘global Maze resource’ to learn about the discovered locations of the barriers / danger areas

Only 1 thread can access it at any one time!

J) Once the program is completed and tested to be working successfully, you are highly encouraged to add on “new features” to the program that you feel are applicable to the task of finding the shortest path thru a maze. Additional marks may be awarded subject to the relevancy and correctness of the new functionalities.

K) Your program should be written in C++, and using the library functions available in header file ‘pthread.h’, to handle all aspects of thread creation, management and synchronization.

L) To encourage good program design, you should consider using different *.cpp class files to encapsulate groups of related methods/functions.

Additional Resources

· After all students have gone through this document, your tutor will hold a special session to discuss / elaborate on the requirements of this assignment.

· In addition, your tutor will hold a Q & A sessions to clarify any issues/doubts you may have on the analysis and design of this multi-threaded program. To ensure a fruitful session, all students must come prepared with their list of questions, so that everybody’s time is efficiently utilized.

Deliverables

1) The deliverables include the following:

a) The actual working shell program (hard+soft copies), with comments on each file, function or block of code to help the tutor understand its purpose.

b) A word document (hard+soft copies) that elaborates on:

· (Interpreted) requirements of the program

· Diagram / Illustrations of program design

· Summary of implementation of each module in your program

· Reflections on program development (e.g. assumptions made, difficulties faced, what could have been done better, possible enhancements in future, what have you learnt , etc)

c) A program demo/evaluation during lab session. You must be prepared to perform certain tasks / answer any questions posed by the tutor.

2) IMPT: Please follow closely, to the submission instructions in Appendix C, which contains details about what to submit, file naming conventions, when to submit, where to submit, etc.

3) The evaluation will be held during lab session where you are supposed to submit your assignment. Some time will be allocated for you to present / demonstrate your program during the session.

Grading

Student’s deliverable will be graded according to the following criteria:

(i) Program fulfills all the basic requirements stipulated by the assignment

The requirements includes some/all of the following:

· Ability to handle maze of different sizes

· No. of danger areas uncovered

· No. of barriers uncovered

· No. of threads utilized

· Validity of the single solution path (a series of Point locations leading from Start to End locations

(ii) Successful demonstration of a working program, clarity of presentation and satisfactory answers provided during Q & A session.

(iii) Additional efforts in enhancing the program with features over and above task requirements, impressive, “killer” presentation and demonstration, etc.

(iv) After the submission of deliverables, students will be required undergo an evaluation process (to determine fulfillment of task requirements.) Further instructions will be given by the Tutor during the subsequent respective labs. Please pay attention as failure to adhere to instructions may result in deduction of marks.

Tutor’s note:

In the real working world, satisfactory completion of your tasks is no longer enough. The ability to add value, communicate and/or demonstrate your ideas with clarity is just as important as correct functioning of your program. The grading criteria is set to imitate such requirements on a ‘smaller scale’.

APPENDIX A

(Sample contents for Maze ‘mazedata.txt’)

Length : 20

Breadth : 10

// ------------------------------

// ----- Start of Maze Data -----

// ------------------------------

// 'S' denotes Starting position

// 'E' denotes Ending position

// '#' denotes Barrier

// 'X' denotes Danger Area

####################

#S # # #

# # ## ## ### ###

# # # # E #

## # # X # X ## #

# X ### ##### #

# # # # # ###

# ### ### ## # #####

# # #

####################

APPENDIX B

(Output solution stored in a generated text, based on the maze configuration in Appendix A)

0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19

0 # # # # # # # # # # # # # # # # # # # #

1 # S # # #

2 # # # # # # # # # # # #

3 # # # # E #

4 # # # # X # X # # #

5 # X # # # # # # # # #

6 # # # # # # # #

7 # # # # # # # # # # # # # # #

8 # # #

9 # # # # # # # # # # # # # # # # # # # #

_length : 20

_breadth : 10

_startLocation : [ 1, 1 ]

_endLocation : [ 17, 3 ]

No. of paths discovered : 0

0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19

0

1 S

2

3 E

4

5

6

7

8

9

_length : 20

_breadth : 10

_startLocation : [ 1, 1 ]

_endLocation : [ 17, 3 ]

No. of paths discovered : 0

0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19

0 # # # # # # # # # # # # # # # # # # # #

1 # S # # #

2 # # # # # # # # # # # #

3 # # # # E #

4 # # # # X # X # # #

5 # X # # # # # # # # #

6 # # # # # # # #

7 # # # # # # # # # # # # # # #

8 # # #

9 # # # # # # # # # # # # # # # # # # # #

Thread 'POOH' has been created !!

Total no. of steps : 1

0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19

0 #

1 S

2

3 E

4

5

6

7

8

9

Total no. of steps : 1

0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19

0 #

1 # S

2

3 E

4

5

6

7

8

9

Total no. of steps : 2

0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19

0 #

1 # S

2 # 1

3 E

4

5

6

7

8

9

Total no. of steps : 3

0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19

0 #

1 # S

2 # 1

3 2 E

4 #

5

6

7

8

9

Total no. of steps : 3

0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19

0 #

1 # S

2 # 1

3 # 2 E

4 #

5

6

7

8

9

Total no. of steps : 5

0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19

0 #

1 # S

2 # 1 4 #

3 # 2 3 E

4 #

5

6

7

8

9

Total no. of steps : 6

0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19

0 # #

1 # S 5

2 # 1 4 #

3 # 2 3 E

4 #

5

6

7

8

9

Total no. of steps : 6

0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19

0 # #

1 # S 5 #

2 # 1 4 #

3 # 2 3 E

4 #

5

6

7

8

9

Thread 'POOH' hits a DEAD END near [2, 1] !!

Thread 'TIGGER' has been created !!

Thread 'ROO' has been created !!

===========================================================

Elapsed Time : 0

Latest Update ...

===========================================================

Dead End Paths Found : 1

Barriers Discovered : 8

Danger Area Discovered : 0

Total no. of steps : 5

0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19

0 # #

1 # S #

2 # 1 #

3 # 2 3 E

4 # 4

5

6

7

8

9

Total no. of steps : 5

0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19

0 # #

1 # S #

2 # 1 #

3 # 2 3 E

4 # 4 #

5

6

7

8

9

Total no. of steps : 6

0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19

0 # #

1 # S #

2 # 1 #

3 # 2 3 E

4 # 4 #

5 5

6 #

7

8

9

Total no. of steps : 7

0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19

0 # #

1 # S #

2 # 1 #

3 # 2 3 E

4 # 4 #

5 6 5

6 #

7

8

9

Total no. of steps : 7

0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19

0 # #

1 # S #

2 # 1 #

3 # 2 3 E

4 # 4 #

5 # 6 5

6 #

7

8

9

Total no. of steps : 8

0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19

0 # #

1 # S #

2 # 1 #

3 # 2 3 E

4 # 4 #

5 # 6 5

6 # 7 #

7

8

9

Total no. of steps : 8

0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19

0 # #

1 # S #

2 # 1 #

3 # 2 3 E

4 # 4 #

5 # 6 5

6 # 7 #

7

8

9

Total no. of steps : 9

0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19

0 # #

1 # S #

2 # 1 #

3 # 2 3 E

4 # 4 #

5 # 6 5

6 # 7 #

7 # 8

8

9

Total no. of steps : 9

0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19

0 # #

1 # S #

2 # 1 #

3 # 2 3 E

4 # 4 #

5 # 6 5

6 # 7 #

7 # 8 #

8

9

Total no. of steps : 10

0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19

0 # #

1 # S #

2 # 1 #

3 # 2 3 E

4 # 4 #

5 # 6 5

6 # 7 #

7 # 8 #

8 9

9 #

Total no. of steps : 10

0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19

0 # #

1 # S #

2 # 1 #

3 # 2 3 E

4 # 4 #

5 # 6 5

6 # 7 #

7 # 8 #

8 # 9

9 #

Total no. of steps : 11

0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19

0 # #

1 # S #

2 # 1 #

3 # 2 3 E

4 # 4 #

5 # 6 5

6 # 7 #

7 # 8 #

8 # 9 10

9 #

Total no. of steps : 11

0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19

0 # #

1 # S #

2 # 1 #

3 # 2 3 E

4 # 4 #

5 # 6 5

6 # 7 #

7 # 8 #

8 # 9 10

9 # #

Total no. of steps : 11

0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19

0 # #

1 # S #

2 # 1 #

3 # 2 3 E

4 # 4 #

5 # 6 5

6 # 7 #

7 # 8 #

8 # 9 10 #

9 # #

Thread 'TIGGER' hits a DEAD END near [2, 1] !!

===========================================================

Elapsed Time : 1

Latest Update ...

===========================================================

Dead End Paths Found : 2

Barriers Discovered : 22

Danger Area Discovered : 0

Thread 'TIGGER' hits a DEAD END near [2, 8] !!

===========================================================

Elapsed Time : 2

Latest Update ...

===========================================================

Dead End Paths Found : 3

Barriers Discovered : 22

Danger Area Discovered : 0

Thread 'ROO' hits a DEAD END near [2, 1] !!

===========================================================

Elapsed Time : 3

Latest Update ...

===========================================================

Dead End Paths Found : 4

Barriers Discovered : 22

Danger Area Discovered : 0

Total no. of steps : 7

0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19

0 # #

1 # S #

2 # 1 #

3 # 2 3 E

4 # 4 #

5 # 5 6

6 # #

7 # #

8 # #

9 # #

Total no. of steps : 8

0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19

0 # #

1 # S #

2 # 1 #

3 # 2 3 E

4 # 4 #

5 # 5 6

6 # # 7

7 # # #

8 # #

9 # #

Total no. of steps : 8

0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19

0 # #

1 # S #

2 # 1 #

3 # 2 3 E

4 # 4 #

5 # 5 6

6 # # 7

7 # # #

8 # #

9 # #

Total no. of steps : 9

0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19

0 # #

1 # S #

2 # 1 #

3 # 2 3 E

4 # 4 #

5 # 5 6

6 # # 7 8

7 # # # #

8 # #

9 # #

Total no. of steps : 9

0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19

0 # #

1 # S #

2 # 1 #

3 # 2 3 E

4 # 4 #

5 # 5 6 X

6 # # 7 8

7 # # # #

8 # #

9 # #

Thread 'TIGGER' stepped into DANGER at [4, 5] !!

===========================================================

Elapsed Time : 4

Latest Update ...

===========================================================

Dead End Paths Found : 4

Barriers Discovered : 26

Danger Area Discovered : 1

Thread 'TIGGER' is dead! It's sacrifice shall not be in vain!

Creating new thread 'GOLPHER'

Thread 'GOLPHER' has been created !!

Thread 'POOH' hits a DEAD END near [2, 8] !!

===========================================================

Elapsed Time : 5

Latest Update ...

===========================================================

Dead End Paths Found : 5

Barriers Discovered : 26

Danger Area Discovered : 1

Total no. of steps : 10

0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19

0 # #

1 # S #

2 # 1 #

3 # 2 3 E

4 # 4 #

5 # 5 6 X

6 # # 7 8 9 #

7 # # # #

8 # #

9 # #

Total no. of steps : 11

0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19

0 # #

1 # S #

2 # 1 #

3 # 2 3 E

4 # 4 #

5 # 5 6 X 10 #

6 # # 7 8 9 #

7 # # # #

8 # #

9 # #

Total no. of steps : 12

0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19

0 # #

1 # S #

2 # 1 #

3 # 2 3 E

4 # 4 # 11 #

5 # 5 6 X 10 #

6 # # 7 8 9 #

7 # # # #

8 # #

9 # #

Total no. of steps : 13

0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19

0 # #

1 # S #

2 # 1 # #

3 # 2 3 12 E

4 # 4 # 11 #

5 # 5 6 X 10 #

6 # # 7 8 9 #

7 # # # #

8 # #

9 # #

Total no. of steps : 13

0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19

0 # #

1 # S #

2 # 1 # #

3 # 2 3 12 # E

4 # 4 # 11 #

5 # 5 6 X 10 #

6 # # 7 8 9 #

7 # # # #

8 # #

9 # #

Total no. of steps : 15

0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19

0 # #

1 # S #

2 # 1 # 14 #

3 # 2 3 13 12 # E

4 # 4 # 11 #

5 # 5 6 X 10 #

6 # # 7 8 9 #

7 # # # #

8 # #

9 # #

Total no. of steps : 15

0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19

0 # #

1 # S #

2 # 1 # 14 #

3 # 2 3 13 12 # E

4 # 4 # 11 #

5 # 5 6 X 10 #

6 # # 7 8 9 #

7 # # # #

8 # #

9 # #

Total no. of steps : 16

0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19

0 # # #

1 # S # 15

2 # 1 # 14 #

3 # 2 3 13 12 # E

4 # 4 # 11 #

5 # 5 6 X 10 #

6 # # 7 8 9 #

7 # # # #

8 # #

9 # #

Total no. of steps : 16

0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19

0 # # #

1 # S # 15

2 # 1 # 14 #

3 # 2 3 13 12 # E

4 # 4 # 11 #

5 # 5 6 X 10 #

6 # # 7 8 9 #

7 # # # #

8 # #

9 # #

Total no. of steps : 17

0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19

0 # # # #

1 # S # 15 16

2 # 1 # 14 #

3 # 2 3 13 12 # E

4 # 4 # 11 #

5 # 5 6 X 10 #

6 # # 7 8 9 #

7 # # # #

8 # #

9 # #

Total no. of steps : 17

0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19

0 # # # #

1 # S # 15 16

2 # 1 # 14 #

3 # 2 3 13 12 # E

4 # 4 # 11 #

5 # 5 6 X 10 #

6 # # 7 8 9 #

7 # # # #

8 # #

9 # #

Total no. of steps : 17

0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19

0 # # # #

1 # S # 15 16 #

2 # 1 # 14 #

3 # 2 3 13 12 # E

4 # 4 # 11 #

5 # 5 6 X 10 #

6 # # 7 8 9 #

7 # # # #

8 # # Thread 'ROO' hits a DEAD END near [2, 8] !!

9 # #

===========================================================

Elapsed Time : 6

Latest Update ...

===========================================================

Dead End Paths Found : 6

Barriers Discovered : 38

Danger Area Discovered : 1

Thread 'ROO' hits a DEAD END near [5, 1] !!

===========================================================

Elapsed Time : 7

Latest Update ...

===========================================================

Dead End Paths Found : 7

Barriers Discovered : 38

Danger Area Discovered : 1

Total no. of steps : 15

0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19

0 # # # #

1 # S # #

2 # 1 # #

3 # 2 3 13 12 # E

4 # 4 # 14 11 #

5 # 5 6 X 10 #

6 # # 7 8 9 #

7 # # # #

8 # #

9 # #

Note :

· There are many pages of other intermediate output that is not feasible to show in this Appendix.

· We are now skipping straight to the ending portion of the output.

· Below output show the LAST FEW STEPS of the thread exploration leading to the discovery of a single, solution path from Start Location ‘S’ to End Location ‘E’ !!

Total no. of steps : 51

0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19

0 # # # # # # # # # # # # # #

1 # S # # 23 24 25 26 33 34 35 36 37

2 # 1 # # # 22 # # 27 32 # # # 38 # #

3 # 2 3 # 21 20 # 28 31 # 40 39 50 49 #

4 # 4 # # 19 # 29 30 41 # # 48 #

5 # 5 6 X # # # 18 # # # # 42 45 46 47 #

6 # # 7 8 9 # 17 # # 43 44 # #

7 # # # # 10 # # # 16 # # # # # # #

8 # # 11 12 13 14 15 #

9 # # # # # # # # # # # # # # # # #

Thread 'ROO' just found a solution! Well done!!

Finished Finding a SAFE PATH !!

Printing submitted maze solution ...

Printing solution for Tan Ah Beng, id : 1001001

--------------------------------------------------------------------------------------------

Total no. of steps : 50

0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19

0 # # # # # # # # # # # # # #

1 # S # # 23 24 25 26 33 34 35 36 37

2 # 1 # # # 22 # # 27 32 # # # 38 # #

3 # 2 3 # 21 20 # 28 31 # 40 39 E 49 #

4 # 4 # # 19 # 29 30 41 # # 48 #

5 # 5 6 X # # # 18 # # # # 42 45 46 47 #

6 # # 7 8 9 # 17 # # 43 44 # #

7 # # # # 10 # # # 16 # # # # # # #

8 # # 11 12 13 14 15 #

9 # # # # # # # # # # # # # # # # #

Total no. of Threads submitting info : 3

Duplicated Paths (to Barriers) submitted : 155

Duplicated Paths (to Danger Area) submitted : 0

Total no. of Barrier ('#') discovered : 90 out of 105 !!

Total no. of Danger Area ('X') discovered : 1 out of 3 !!

Printing Thread Statistics !!

--------------------------------------------------------------------------------------------

Stats for Thread ID : 3070360432

Found Solution Path : No ...

UNIQUE Path to barriers discovered : 26

DUPLICATED Path to barriers submitted : 0

UNIQUE Path to danger areas discovered : 1

DUPLICATED Path to danger areas submitted : 0

**********************************************************************

Stats for Thread ID : 3061967728

Found Solution Path : YES !!

UNIQUE Path to barriers discovered : 103

DUPLICATED Path to barriers submitted : 0

UNIQUE Path to danger areas discovered : 0

DUPLICATED Path to danger areas submitted : 0

**********************************************************************

Stats for Thread ID : 3078753136

Found Solution Path : No ...

UNIQUE Path to barriers discovered : 22

DUPLICATED Path to barriers submitted : 0

UNIQUE Path to danger areas discovered : 0

DUPLICATED Path to danger areas submitted : 0

**********************************************************************

APPENDIX C

Submission Instructions (V. IMPT!!)

1) Deliverables

a) All submissions should be in softcopy, unless otherwise instructed

b) For the actual files to be submitted, you typically need to include the following:

· word document report (e.g. *.doc), save as MS Word 97-2003 format

· the source file(s), (e.g. *.sh, *.c, *.h, *.o, or *.cpp files)

· the executable file, compile into an executable file with *.exe

(e.g. Assn3.exe). Note: this only applies to non-shell script assignments!

2) How to package

Compress all your assignment files into a single zip file. Please use the following naming format :

<FT/PT>_Assn3_<Stud. No.>_<Name>.zip

Example : FT_Assn3_1234567_JohnDoeAnderson. zip

· <FT/PT> Use “FT” for Full-Time student, “PT” if you are Part-Time student

· Assn3 if you are submitting assignment 3, Assn1 if submitting assignment 1 etc.

· <Stud. No.> refers to your UOW student number (e.g. 1234567)

· <Name> refers to your UOW registered name (e.g. JohnDoeAnderson)

3) Where to submit

Please submit your assignment via Moodle eLearning site.

In the event of UNFORSEEN SITUATIONS :

( E.g. Student's moodle account not ready, cannot login to moodle, eLearning site down on submission day, unable to upload assignment, etc )

Please email your single zip file to your tutor at :

[email protected] for FULL TIME students

(To be announced) for PART TIME students

In your email subject line, type in the following information :

<FT/PT> <assignment info> <student number> and <name>.

Example:

To : tutor's email (see above)

Subject : FT Assn3 1234567 JohnDoeAnderson

Note 1 : The timestamp shown on tutor’s email Inbox will be used to determine if the assignment is late or not.

Note 2 : After email submission, your mailbox’s sent folder would have a copy (record) of your sent email, please do not delete that copy !! It could be used to prove your timely submission, in case the Tutor did not receive your email!

4) When to submit

a) Depending on the time-table, a demo / evaluation for your assignment may be scheduled during the 3rd - 5th lab session for the semester (i.e. lab 3 - 5).

Please consult your tutor for further details. Some time may be allocated for each student to present / explain your system design during the session.

Please submit your files 1 day before the start of your demo / evaluation lab session.

b) To illustrate, please refer to the following table on the different submission events and deadlines

Assignment

Email Submisson to reach Tutor’s Inbox by :

Assignment Evaluation (Tasks)

Email Evaluation files by :

1

Night before Lab - 2(PT), 3(FT)

Lab 2(PT), 3(FT)

End of Lab 2(PT), 3(FT)

2

Night before Lab - 3(PT), 4(FT)

Lab 3(PT), 4(FT)

End of Lab 3(PT), 4(FT)

3

Night before Lab - 4(PT), 5(FT)

Lab 4(PT), 5(FT)

End of Lab 4(PT), 5(FT)

Note: (PT) = Part Time Students, (FT) = Full Time Students !

c) For example, for Full Time (FT) students submitting Assignment 3, if Lab 5 falls on 24 / 02 / 2017, then

· Submit your zip file to Tutor by 23 / 02 / 2017, 2300 hrs (nite b4 Lab 5)

· Setup your program for evaluation on 24 / 02 / 2017 (Lab 5)

· Finish evaluation tasks, email files on 24 / 02 / 2017 (end of Lab 5)

5) Please help by paying attention to the following …

! VERY IMPORTANT !

PLEASE FOLLOW THE GUIDELINES IN ALL ASSIGNMENT APPENDICES !!

PLEASE FOLLOW THE SUBMISSION INSTRUCTIONS FROM 1 TO 4 !!

IF YOU ARE NOT SURE,

PLEASE CHECK WITH YOUR TUTOR DURING LABS / LECTURES !

OR ...

PLEASE EMAIL YOUR ENQUIRIES TO YOUR TUTOR !

MARKS WILL BE DEDUCTED IF YOU FAIL TO FOLLOW INSTRUCTIONS !!

Example :

· Your report document or zip file does not follow naming convention

· Your email address does not include your name (i.e. cannot be used to identify sender)

· You have no email subject

· Wrong naming or misleading information given

(e.g. putting “Assn2” in email subject, when you are submitting “Assn1”)

(e.g. naming “Assn1” in your zip file, but inside contains Assn2 files )

· Your submission cannot be downloaded and unzipped

· Your report cannot be opened by Microsoft Word / Access

· Your program cannot be re-compiled and/or executable file cannot run

6) Re-submission administration

After the deadline, (on case-by-case basis), some students / grp may be granted an opportunity for an un-official resubmission by the tutor. If this is so, please adhere to the following instructions carefully:

<Step 1>

Zip up for re-submission files according to the following format :

<FT/PT>_Assn3_Resubmit_v1_<Stud. No.> _<Name>.zip

Example : FT _ Assn3_Resubmit_v1_1234567_JohnDoeAnderson. zip

· <FT/PT> Use “FT” for Full-Time student, “PT” if you are Part-Time student

· Assn3 if you are submitting assignment 3, Assn1 if submitting assignment 1 etc.

· Resubmit_v1 if this is your 1st re-submission

· Resubmit_v2 if this is your 2nd re-submission

· <Stud. No.> refers to your UOW student number (e.g. 1234567)

· <Name> refers to your UOW registered name (e.g. JohnDoeAnderson)

· V. IMPT - To prevent Tutor’s Inbox from blowing up in his face, each student is only allowed to re-submit twice, for each assignment only!

<Step 2>

Please email your single zip file to your tutor's email (refer to section 3) - Where to submit)

In your email subject line, type in the following information :

<FT/PT> <assignment info> <re-submission ver.> <student number> and <name>

Example:

To : tutor's email (refer to section 3) - Where to submit)

Subject : FT Assn3 Resubmit_v1 1234567 JohnDoeAnderson

Page 20 of 22

bonus ttest file/Maze (4).o

bonus ttest file/Maze (5).o

bonus ttest file/Maze.h

#ifndef MAZE_H #define MAZE_H // ------------------------------------------------------------------------------------ #include <iomanip> // setw #include <string> // for string manipulation ... #include <iostream> // cout, endl #include <fstream> // for file i/o ... #include "Assignm3_Utils.h" // ------------------------------------------------------------------------------------ namespace Assignm3 { const char DANGER_CHAR = 'X'; const char BARRIER_CHAR = '#'; const char END_POS_CHAR = 'E'; const char START_POS_CHAR = 'S'; const int DANGER_INT = -10; const int BARRIER_INT = -11; const int END_POS_INT = -22; const int START_POS_INT = -33; const int UNINITIALIZED_VALUE = -99; const std::string DefaultMazeFilename = "mazedata.txt"; /* const std::string DefaultMazeFilename = "High_Casualties.txt"; const std::string DefaultMazeFilename = "Freedom.txt"; const std::string DefaultMazeFilename = "My_Only_Way.txt"; const std::string DefaultMazeFilename = "Horizontals.txt"; const std::string DefaultMazeFilename = "Verticals.txt"; const std::string DefaultMazeFilename = "Diagonals.txt"; const std::string DefaultMazeFilename = "Horizontals1.txt"; const std::string DefaultMazeFilename = "Verticals1.txt"; const std::string DefaultMazeFilename = "Frustration.txt"; const std::string DefaultMazeFilename = "Checkered.txt"; const std::string DefaultMazeFilename = "Choices.txt"; const std::string DefaultMazeFilename = "Checkered_Upsize.txt"; */ const std::string MAZE_LENGTH_KEYWORD = "Length : "; const std::string MAZE_BREADTH_KEYWORD = "Breadth : "; class Maze { public: // Constructor ... Maze (int length=0, int breadth=0); Maze (int length, int breadth, Point startLocation, Point endLocation); // Destructor ... ~Maze (void); void LoadMaze (const std::string filename=DefaultMazeFilename); void SaveMaze (const std::string filename=DefaultMazeFilename) const; VectorOfVectorOfPointStructType getPathVector (void) const; VectorOfPointStructType getShortestPath (void) const; int getLength (void) const; int getBreadth (void) const; void setStartLocation (Point p); void setEndLocation (Point p); Point getStartLocation (void) const; Point getEndLocation (void) const; int getNoOfDangerChar (void) const; int getNoOfBarrierChar (void) const; void updateMaze (Point p, int data); bool IsThereDanger (int x, int y) const; bool IsThereBarrier (int x, int y) const; bool IsThereDanger (Point aLocation) const; bool IsThereBarrier (Point aLocation) const; void AddNewPath (VectorOfPointStructType newPath); void DisplayInfo (std::ostream &outputStream=std::cout) const; void DisplayMaze (void) const; void DisplayMaze (int * mazeArray, std::ostream &outputStream=std::cout, int field_width=1) const; // display path as graphically via an array of '2D maze' data void ShowPathGraphically (VectorOfPointStructType & pointStructVector, std::ostream &outputStream=std::cout); private: int _length; int _breadth; Point _startLocation; Point _endLocation; // 1D array representing a 2D maze of chars ... int * _mazeArray; // A 'path' consists of a series of Point structs plotting // a course from _startLocation to _endLocation // // Below data structure is used to store all valid paths // discovered in _mazeArray VectorOfVectorOfPointStructType _pathVector; void InitMazeArray (void); void ReadLengthData (std::string aLine); void ReadBreadthData (std::string aLine); void ReadMazeData (std::string aLine, int & currRowIndex); void SaveMazeArray (int * mazeArray, std::ostream &outputStream) const; }; // end class Maze ... } // end namespace Assignm3 ... #endif // MAZE_H

bonus ttest file/mazedata.txt

Length : 20 Breadth : 10 // ------------------------------ // ----- Start of Maze Data ----- // ------------------------------ // 'S' denotes Starting position // 'E' denotes Ending position // '#' denotes Barrier // 'X' denotes Danger Area #################### #S # # # # # ## ## ### ### # # # # E # ## # # X # X ## # # X ### ##### # # # # # # ### # ### ### ## # ##### # # # ####################

bonus ttest file/Path (1).o

bonus ttest file/Path (2).o

bonus ttest file/Path.h

#ifndef PATH_H #define PATH_H // ------------------------------------------------------------------------------------ #include <iostream> // cout, endl #include "Assignm3_Utils.h" // ------------------------------------------------------------------------------------ namespace Assignm3 { class Path { public: // Constructor ... Path (void); // Destructor ... ~Path (void); // returns true of a Point is found in a vector of Points ... bool isLocationInPath (Point & location, VectorOfPointStructType & pointStructVector) const; // display path as series of [x, y] coordinates void displayPath (VectorOfPointStructType & pointStructVector, std::ostream &outputStream=std::cout, int maxDataPerLine=8) const; // check if 2 paths are identical ... bool arePathsIdentical (VectorOfPointStructType & firstPath, VectorOfPointStructType & secondPath) const; private: }; // end class Path ... } // end namespace Assignm3 ... #endif // PATH_H

bonus ttest file/ProgramLog.h

#ifndef PROGRAM_LOG_H #define PROGRAM_LOG_H #include <string> #include <iostream> #include <errno.h> // ------------------------------------------------------------------------------------ static void WriteLogMessage (std::ostream & outputStream, std::string message) { if (outputStream.good()) outputStream << message << std::endl; else { std::cout << std::endl; std::cout << "WriteLogMessage Error! outputStream.good() fails! Re-direct Log Msg to screen!" << std::endl; std::cout << "Log Msg : " << message << std::endl; std::cout << std::endl; } } // end WriteLogMessage () ... // ------------------------------------------------------------------------------------ #endif // PROGRAM_LOG_H ...

bonus ttest file/SubmitMazeSoln (1).o

bonus ttest file/SubmitMazeSoln (2).o

bonus ttest file/SubmitMazeSoln.h

#ifndef SUBMIT_MAZE_SOLN_H #define SUBMIT_MAZE_SOLN_H // ------------------------------------------------------------------------------------ #include <string> #include <vector> #include <iostream> // cout, endl #include <pthread.h> // pthread_t #include "Path.h" #include "Maze.h" #include "ProgramLog.h" #include "Assignm3_Utils.h" // ------------------------------------------------------------------------------------ // // How to compile : // // E.g. Assume your main program is called "MyProg.cpp", and you want your executable to be called "MyProg" ... // // g++ MyProg.cpp SubmitMazeSoln.o Path.o Maze.o -o MyProg -lpthread // // Note : the compiled versions of Path.o, Maze.o and SubmitMazeSoln.o are made available to you! // In addition, the headers Path.h, Maze.h and SubmitMazeSoln.h are also made available to you! // // Your task is to concentrate on implementing a multi-threaded program to discover paths // to barrier, danger area and a solution to travel from Start to End locations !!! // // ------------------------------------------------------------------------------------ namespace Assignm3 { // ------------------------------------------------------------------------------------ const std::string DefaultSolutionFilename = "mazesoln.txt"; struct ThreadStatisticsInfo { pthread_t threadID; VectorOfPointStructType solutionPath; // A vector of ALL UNIQUE paths to barriers discovered by this thread VectorOfVectorOfPointStructType submittedPathsToBarriers; // To check if student follows instructions. By right a thread should only discover // ONE path to danger area before being destroyed ! VectorOfVectorOfPointStructType submittedPathsToDangerAreas; // Below var will be incremented, if same path to barrier is submitted again and again // by this thread! int noOfDuplicatedPathsToBarrier; // Below var will be incremented, if same path to danger area is submitted again and again // by this thread! int noOfDuplicatedPathsToDangerArea; ThreadStatisticsInfo (void) { noOfDuplicatedPathsToBarrier = 0; noOfDuplicatedPathsToDangerArea = 0; solutionPath = VectorOfPointStructType (); submittedPathsToBarriers = VectorOfVectorOfPointStructType (); submittedPathsToDangerAreas = VectorOfVectorOfPointStructType (); } ~ThreadStatisticsInfo (void) { solutionPath.clear (); submittedPathsToBarriers.clear (); submittedPathsToDangerAreas.clear (); } }; // type define a vector of 'ThreadStatisticsInfo' ... typedef std::vector<ThreadStatisticsInfo> VectorOfThreadStatisticsInfoType; // ------------------------------------------------------------------------------------ class SubmitMazeSoln { public: // Constructor ... SubmitMazeSoln (void); // Destructor ... ~SubmitMazeSoln (void); // Student should call this method to 'submit' an EXPLORED PATH to danger area 'X' // discovered by one of his/her generated thread! // // Parameter 1 : pthread_t => refers to the id of the thread that explored the path to discover the Danger Area // // Parameter 2 : VectorOfPointStructType => refers to a vector of (x, y) Points, containing the path explored by the thread // from start location to Danger Area's location! // // Note : Parameter 2 must contain start location Point at the beginning of the vector (i.e. pathToDangerArea [0]) , AND // the Danger Area Point at the end of the vector (i.e. pathToDangerArea [size-1] !!) // // returns 'true' if the submitted discovery is UNIQUE // returns 'false' if : // a) first Point in 'pathToDangerArea' does NOT contain the start location of the maze OR // b) submitted Danger Area's location is wrong OR // c) same path has been submitted before OR // d) points in the path are NOT CONNECTED, or CONTAINS OTHER DANGER / BARRIER or DUPLICATED POINTS OR // e) threadID is invalid OR // f) 'pathToDangerArea' is empty // bool submitPathToDangerArea (pthread_t threadID, VectorOfPointStructType & pathToDangerArea); // Student should call this method to 'submit' an EXPLORED PATH to barrier '#' // discovered by one of his/her generated thread! // // Parameter 1 : pthread_t => refers to the id of the thread that explored the path to discover the Barrier // // Parameter 2 : VectorOfPointStructType => refers to a vector of (x, y) Points, containing the path explored by the thread // from start location to Barrier's location! // // Note : Parameter 2 must contain start location Point at the beginning of the vector (i.e. pathToBarrier [0]) , AND // the Barrier Point at the end of the vector (i.e. pathToBarrier [size-1] !!) // // returns 'true' if the submitted discovery is UNIQUE // returns 'false' if : // a) first Point in 'pathToBarrier' does NOT contain the start location of the maze OR // b) submitted Barrier's location is wrong OR // c) same path has been submitted before OR // d) points in the path are NOT CONNECTED, or CONTAINS OTHER DANGER / BARRIER or DUPLICATED POINTS // e) threadID is invalid OR // f) 'pathToBarrier' is empty // bool submitPathToBarrier (pthread_t threadID, VectorOfPointStructType & pathToBarrier); // Student should call this method to 'submit' a SOLUTION PATH to end location 'E' // discovered by one of his/her generated thread! // // Parameter 1 : pthread_t => refers to the id of the thread that explored the path to discover the solution // // Parameter 2 : VectorOfPointStructType => refers to a vector of (x, y) Points, containing the path explored by the thread // from start location to end location! // // returns 'true' if the submitted solution is VALID // returns 'false' if the submitted solution is INVALID ... // // A student's solution is valid if his submitted solution : // // i) beginning of the 'pathToEndLocation' vector contains the Start Location // ii) end of the 'pathToEndLocation' vector contains the End Location // iii) contains a series of 'connected' points from start to end location // iv) there are no 'barriers' or 'danger' locations in his submitted path // v) each point in his submitted path is unique (i.e. the path must not travel in loops/circles) ... // vi) the BEGINNING point must be 'Start Location' and the END point must be 'End Location' ... bool submitSolutionPath (pthread_t threadID, VectorOfPointStructType & pathToEndLocation); // Once ALL explored paths and solution are submitted, student MUST call below method, // to print the details of their solution on screen! // // Parameter 1 : 'studentName' => the full name of the student, (without spaces) // E.g. 'Tan Ah Beng' should be changed to 'TanAhBeng' (without spaces) !! // // Parameter 2 : 'studentID' => the admin. or matric. no. of the student // E.g. '1234567' // void printSubmittedSolution (std::string studentName, std::string studentID, std::ostream &outputStream=std::cout); // Once ALL explored paths and solution are submitted, student MUST call below method, // to save the details of their solution to a text file! // // Parameter 1 : 'studentName' => the full name of the student, (without spaces) // E.g. 'Tan Ah Beng' should be changed to 'TanAhBeng' (without spaces) !! // // Parameter 2 : 'studentID' => the admin. or matric. no. of the student // E.g. '1234567' // void saveSubmittedSolution (std::string studentName, std::string studentID); private: Maze * _problemMaze; Maze * _studentSolnMaze; int _noOfDuplicatedPathsToBarrierSubmitted; int _noOfDuplicatedPathsToDangerAreaSubmitted; VectorOfPointStructType _finalSolutionPath; VectorOfVectorOfPointStructType _discoveredPathsToBarrier; VectorOfVectorOfPointStructType _discoveredPathsToDangerArea; VectorOfThreadStatisticsInfoType _generatedThreadsVector; int findThreadIndex (pthread_t threadID) const; // a helper function invoked by other functions (e.g. 'isSolutionValid ()') to check path validity ... bool checkPathValidity (VectorOfPointStructType aPath) const; bool isPathUnique (VectorOfPointStructType submittedNewPath, VectorOfVectorOfPointStructType discoveredPaths) const; void storeThreadInfo ( pthread_t threadID, VectorOfPointStructType & aPath, int typeOfPath ); }; // end class SubmitMazeSoln ... } // end namespace Assignm3 ... #endif // SUBMIT_MAZE_SOLN_H // Statistics to report ... // // 1) No. of unique threads generated // // 2) No. of danger areas discovered // // 3) Count of duplicated paths (to danger areas) submitted // // E.g. of threadID ... '3079273328'

bonus ttest file/testmaze.cpp

bonus ttest file/testmaze.cpp


//
// To compile this program into an executable named 'testmaze', ...
//
// 1) Ensure all downloaded files are in the SAME folder
// 
// 2) Use the following command : 
//    g++ testmaze.cpp Maze.o -o testmaze
//

#include   "Maze.h"
#include   "Assignm3_Utils.h"

const  std :: string filename  =   "mazedata.txt" ;

int  main  ( void )
{

     Assignm3 :: Maze   * maze  =   new   Assignm3 :: Maze   ();

    maze -> LoadMaze   ( filename );

    std :: cout  <<  std :: endl ;
    std :: cout  <<   "Length  of maze in '"   <<  filename  <<   "' : "   <<  maze -> getLength ();
    std :: cout  <<  std :: endl ;
    std :: cout  <<   "Breadth of maze in '"   <<  filename  <<   "' : "   <<  maze -> getBreadth ();
    std :: cout  <<  std :: endl ;

     Point  startLoc  =  maze -> getStartLocation ();
     Point  endLoc    =  maze -> getEndLocation ();

    std :: cout  <<   "Start Location of maze in '"   <<  filename  <<   "' : " ;
    startLoc . display ();
    std :: cout  <<  std :: endl ;

    std :: cout  <<   "End   Location of maze in '"   <<  filename  <<   "' : " ;
    endLoc . display ();
    std :: cout  <<  std :: endl ;

    std :: cout  <<  std :: endl ;
    std :: cout  <<   "Displaying Maze contents ..." ;
    std :: cout  <<  std :: endl ;
    maze -> DisplayMaze   ();

    std :: cout  <<  std :: endl ;
    std :: cout  <<  std :: endl ;

}


bonus ttest file/TestSubmitMazeSoln.cpp

bonus ttest file/TestSubmitMazeSoln.cpp


#include   < pthread . h >

#include   "Path.h"
#include   "Maze.h"
#include   "SubmitMazeSoln.h"
#include   "Assignm3_Utils.h"

#include   < stdlib . h >
#include   < stdio . h >
#include   < string . h >


// To compile, 
// 1) Ensure all the necessary header files (see above) are in the same directory
// 2) g++ Path.o Maze.o SubmitMazeSoln.o TestSubmitMazeSoln.cpp -o TestSubmitMazeSoln.exe -lpthread


// #######################################################################################

main  ()
{
     Assignm3 :: Path  path ;
     Assignm3 :: SubmitMazeSoln  sms ;

     VectorOfPointStructType  pathToBarrier1  =   VectorOfPointStructType   ();
     VectorOfPointStructType  pathToBarrier2  =   VectorOfPointStructType   ();
     VectorOfPointStructType  pathToBarrier3  =   VectorOfPointStructType   ();
     VectorOfPointStructType  pathToBarrier4  =   VectorOfPointStructType   ();
     VectorOfPointStructType  pathToBarrier5  =   VectorOfPointStructType   ();

    pathToBarrier1 . push_back  ( Point   ( 1 , 1 ));
    pathToBarrier1 . push_back  ( Point   ( 0 , 1 ));

    pathToBarrier2 . push_back  ( Point   ( 1 , 1 ));
    pathToBarrier2 . push_back  ( Point   ( 1 , 0 ));

    pathToBarrier3 . push_back  ( Point   ( 1 , 1 ));
    pathToBarrier3 . push_back  ( Point   ( 1 , 2 ));
    pathToBarrier3 . push_back  ( Point   ( 0 , 2 ));

    pathToBarrier4 . push_back  ( Point   ( 1 , 1 ));
    pathToBarrier4 . push_back  ( Point   ( 1 , 2 ));
    pathToBarrier4 . push_back  ( Point   ( 1 , 3 ));
    pathToBarrier4 . push_back  ( Point   ( 1 , 4 ));

    pathToBarrier5 . push_back  ( Point   ( 1 , 1 ));
    pathToBarrier5 . push_back  ( Point   ( 1 , 2 ));
    pathToBarrier5 . push_back  ( Point   ( 1 , 4 ));

//  path.displayPath (pathToBarrier1);
//  path.displayPath (pathToBarrier2);
//  path.displayPath (pathToBarrier3);
//  path.displayPath (pathToBarrier4);
//  path.displayPath (pathToBarrier5);

    sms . submitPathToBarrier  (( pthread_t )   1234567 ,  pathToBarrier1 );
    sms . submitPathToBarrier  (( pthread_t )   1234567 ,  pathToBarrier2 );
    sms . submitPathToBarrier  (( pthread_t )   1234567 ,  pathToBarrier3 );
    sms . submitPathToBarrier  (( pthread_t )   1234567 ,  pathToBarrier4 );
    sms . submitPathToBarrier  (( pthread_t )   1234567 ,  pathToBarrier5 );
    

     VectorOfPointStructType  pathToDangerArea1  =   VectorOfPointStructType   ();
     VectorOfPointStructType  pathToDangerArea2  =   VectorOfPointStructType   ();
     VectorOfPointStructType  pathToDangerArea3  =   VectorOfPointStructType   ();
     VectorOfPointStructType  pathToDangerArea4  =   VectorOfPointStructType   ();
     VectorOfPointStructType  pathToDangerArea5  =   VectorOfPointStructType   ();

    pathToDangerArea1 . push_back  ( Point   ( 1 , 1 ));
    pathToDangerArea1 . push_back  ( Point   ( 2 , 1 ));
    pathToDangerArea1 . push_back  ( Point   ( 3 , 1 ));
    pathToDangerArea1 . push_back  ( Point   ( 4 , 1 ));

    pathToDangerArea2 . push_back  ( Point   ( 1 , 1 ));
    pathToDangerArea2 . push_back  ( Point   ( 2 , 1 ));
    pathToDangerArea2 . push_back  ( Point   ( 2 , 2 ));
    pathToDangerArea2 . push_back  ( Point   ( 2 , 3 ));
    pathToDangerArea2 . push_back  ( Point   ( 3 , 3 ));
    pathToDangerArea2 . push_back  ( Point   ( 4 , 3 ));
    pathToDangerArea2 . push_back  ( Point   ( 4 , 2 ));
    pathToDangerArea2 . push_back  ( Point   ( 4 , 1 ));
//  pathToDangerArea2.push_back (Point (4,0));


    sms . submitPathToDangerArea  (( pthread_t )   1234567 ,  pathToDangerArea1 );
    sms . submitPathToDangerArea  (( pthread_t )   1234567 ,  pathToDangerArea2 );



     VectorOfPointStructType  solutionPath  =   VectorOfPointStructType   ();
    solutionPath . push_back  ( Point   ( 1 , 1 ));
    solutionPath . push_back  ( Point   ( 1 , 2 ));
    solutionPath . push_back  ( Point   ( 1 , 3 ));
    solutionPath . push_back  ( Point   ( 2 , 3 ));
    solutionPath . push_back  ( Point   ( 2 , 4 ));
    solutionPath . push_back  ( Point   ( 2 , 5 ));
    solutionPath . push_back  ( Point   ( 3 , 5 ));
    solutionPath . push_back  ( Point   ( 4 , 5 ));
    solutionPath . push_back  ( Point   ( 4 , 4 ));
    solutionPath . push_back  ( Point   ( 4 , 3 ));

    sms . submitSolutionPath  (( pthread_t )   1234567 ,  solutionPath );  


    sms . printSubmittedSolution  ( "Tan Ah Beng" ,   "1001001" );

    sms . saveSubmittedSolution  ( "Tan Ah Beng" ,   "1001001" );


}     // end main () ...

// #######################################################################################

/*
TESTED!! -> Point struct '==' and '=' operator overloading ...

    Point p (3, 8);

    Point p1 (3, 8);

    Point p2 (8, 8);


    if (p == p1)
    {
        std::cout << "p ";  p.display ();
        std::cout << " is EQUAL to p1 ";    p1.display ();
        std::cout << " !!" << std::endl;
    }
    else
    {
        std::cout << "p ";  p.display ();
        std::cout << " is NOT EQUAL to p1 ";    p1.display ();
        std::cout << " !!" << std::endl;
    }


    if (p == p2)
    {
        std::cout << "p ";  p.display ();
        std::cout << " is EQUAL to p2 ";    p2.display ();
        std::cout << " !!" << std::endl;
    }
    else
    {
        std::cout << "p ";  p.display ();
        std::cout << " is NOT EQUAL to p2 ";    p2.display ();
        std::cout << " !!" << std::endl;
    }


    Point p3 (8, 8);

    Point p4, p5;

    p4 = p5 = p3;
//  p5 = p4;

    std::cout << "p3 is "; p3.display (); std::cout << std::endl;
    std::cout << "p4 is "; p4.display (); std::cout << std::endl;
    std::cout << "p5 is "; p5.display (); std::cout << std::endl;



*/

// #######################################################################################

/*
TESTED !! -> isConnected() in struct Point ...

    Point p (3, 8);
    Point pLeft (2, 8);
    Point pRight (4, 8);
    Point pUp (3, 9);
    Point pDown (3, 7);

    if (p.isConnected (pLeft))
        std::cout << "p is connected to pLeft !!" << std::endl;

    if (p.isConnected (pRight))
        std::cout << "p is connected to pRight !!" << std::endl;

    if (p.isConnected (pUp))
        std::cout << "p is connected to pUp !!" << std::endl;

    if (p.isConnected (pDown))
        std::cout << "p is connected to pDown !!" << std::endl;

    if (pLeft.isConnected (pRight))
        std::cout << "pLeft is connected to pRight !!" << std::endl;
    else
        std::cout << "pLeft is NOT connected to pRight !!" << std::endl;
    
    if (pUp.isConnected (pDown))
        std::cout << "pUp is connected to pDown !!" << std::endl;
    else
        std::cout << "pUp is NOT connected to pDown !!" << std::endl;
*/

// #######################################################################################

/*
TESTED!! -> new method in Path.h 'arePathsIdentical ()' ...
    Point p (3, 8);
    Point p1 (3, 8);
    Point p2 (8, 8);

    VectorOfPointStructType path1;
    path1.push_back (p);    path1.push_back (p1);   path1.push_back (p2);

    VectorOfPointStructType path2;
    path2.push_back (p);    path2.push_back (p1);   path2.push_back (p2);


    Assignm3::Path path;

    if (path.arePathsIdentical (path1, path2))
        std::cout << "path1 is identical to path2 !!" << std::endl;
    else
        std::cout << "path1 is different from path2 !!" << std::endl;


*/

// #######################################################################################

/*
TESTED !! -> Maze constructor, and new methods () ...

    Assignm3::Maze * probMaze = new Assignm3::Maze ();
    probMaze->LoadMaze ();

    Assignm3::Maze * solnMaze = new Assignm3::Maze (probMaze->getLength(), probMaze->getBreadth(),
                                                    probMaze->getStartLocation(), probMaze->getEndLocation());

    probMaze->DisplayMaze ();
    probMaze->DisplayInfo ();

    solnMaze->updateMaze (Point (0,0), Assignm3::BARRIER_INT);
    solnMaze->updateMaze (Point (0,1), Assignm3::BARRIER_INT);
    solnMaze->updateMaze (Point (1,0), Assignm3::BARRIER_INT);

    solnMaze->DisplayMaze ();
    solnMaze->DisplayInfo ();


*/

// #######################################################################################

/*
TESTED !! -> 


*/

// #######################################################################################