Compare commits
2 commits
bc7d3529c2
...
be91ee279b
| Author | SHA1 | Date | |
|---|---|---|---|
| be91ee279b | |||
| 203516e290 |
4 changed files with 67 additions and 6 deletions
|
|
@ -1,6 +1,6 @@
|
||||||
CC = gcc -Wall
|
CC = gcc -Wall
|
||||||
SOURCES = PA04_Main.c StateUtilities_LogN.c Console_IO_Utility.c File_Input_Utility.c File_Output_Utility.c
|
SOURCES = PA04_Main.c BasicUtilities.c RoomUtilities.c CourseUtilities.c Console_IO_Utility.c File_Input_Utility.c File_Output_Utility.c
|
||||||
OBJECTS = PA04_Main.o StateUtilities_LogN.o Console_IO_Utility.o File_Input_Utility.o File_Output_Utility.o
|
OBJECTS = PA04_Main.o BasicUtilities.o RoomUtilities.o CourseUtilities.o Console_IO_Utility.o File_Input_Utility.o File_Output_Utility.o
|
||||||
|
|
||||||
# Uses the template structure defined in the TypicalUtils folder
|
# Uses the template structure defined in the TypicalUtils folder
|
||||||
|
|
||||||
|
|
|
||||||
BIN
PA04-0927/PA04_Main
Executable file
BIN
PA04-0927/PA04_Main
Executable file
Binary file not shown.
|
|
@ -31,7 +31,7 @@ int main( int argc, char **argv )
|
||||||
rooms = createRoomArray( MAX_NUM_ROOMS );
|
rooms = createRoomArray( MAX_NUM_ROOMS );
|
||||||
courses = createCourseArray( MAX_NUM_COURSES );
|
courses = createCourseArray( MAX_NUM_COURSES );
|
||||||
|
|
||||||
if( uploadData( "in_1.txt", courses, rooms ) )
|
if( uploadData( "InputFiles/in_6.txt", courses, rooms ) )
|
||||||
{
|
{
|
||||||
printf( "Start Solution Search\n" );
|
printf( "Start Solution Search\n" );
|
||||||
|
|
||||||
|
|
@ -87,9 +87,70 @@ Dependencies: available tools as needed
|
||||||
bool fitClassRooms( CourseArrayType *courses,
|
bool fitClassRooms( CourseArrayType *courses,
|
||||||
RoomArrayType *rooms, int roomLevel, bool verboseFlag )
|
RoomArrayType *rooms, int roomLevel, bool verboseFlag )
|
||||||
{
|
{
|
||||||
// TODO: Create recursive backtracking function
|
int arrayIterator;
|
||||||
// to find correct assignment of specified courses to available c Rooms
|
RoomDataType tempClassRoom;
|
||||||
|
CourseDataType tempCourse;
|
||||||
|
char buildingString[STD_STR_LEN];
|
||||||
|
char courseString[STD_STR_LEN];
|
||||||
|
// If all courses have been placed
|
||||||
|
// return true
|
||||||
|
if(roomLevel == rooms->size)
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
// setup for current classroom
|
||||||
|
deepCopyRoom(&tempClassRoom, rooms->array[roomLevel]);
|
||||||
|
deepCopyCourse(&tempCourse, courses->array[roomLevel]);
|
||||||
|
setRoomDataString(buildingString, tempClassRoom);
|
||||||
|
if(verboseFlag)
|
||||||
|
{
|
||||||
|
printf("\nRecursion Level %d: Seeking a fit for %s\n", roomLevel, buildingString);
|
||||||
|
}
|
||||||
|
for(arrayIterator = 0; arrayIterator < courses->size; arrayIterator++)
|
||||||
|
{
|
||||||
|
if(verboseFlag)
|
||||||
|
{
|
||||||
|
printSpaces(2);
|
||||||
|
}
|
||||||
|
// For Loop (Increments through courses)
|
||||||
|
if(courses->array[arrayIterator].available &&
|
||||||
|
tempClassRoom.roomCapacity > courses->array[arrayIterator].size)
|
||||||
|
{
|
||||||
|
// Test to find classroom
|
||||||
|
// If open and less than course size
|
||||||
|
// Set classroom associated index to course
|
||||||
|
rooms->array[roomLevel].associatedIndex = arrayIterator;
|
||||||
|
// Set course as unavailable
|
||||||
|
courses->array[arrayIterator].available = false;
|
||||||
|
setCourseDataString(courseString, courses->array[arrayIterator]);
|
||||||
|
if(verboseFlag)
|
||||||
|
{
|
||||||
|
printSpaces(2);
|
||||||
|
printf("Trying Course Name: %s, Course Size: %d - Success!\n", courses->array[arrayIterator].courseName, courses->array[arrayIterator].size);
|
||||||
|
printSpaces(6);
|
||||||
|
printf("Course Name: %s, Course Size: %d will fit in %s\n", tempCourse.courseName, tempCourse.size, buildingString);
|
||||||
|
}
|
||||||
|
// Call and check next recursion
|
||||||
|
if(fitClassRooms(courses, rooms, roomLevel + 1, verboseFlag))
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
// Unset classroom associated index to course
|
||||||
|
tempClassRoom.associatedIndex = NO_CLASS;
|
||||||
|
// Set course as available
|
||||||
|
courses->array[arrayIterator].available = true;
|
||||||
|
}
|
||||||
|
if(verboseFlag)
|
||||||
|
{
|
||||||
|
printf(" Trying Course Name: %s, Course Size: %d - Failed!\n", courses->array[arrayIterator].courseName, courses->array[arrayIterator].size);
|
||||||
|
}
|
||||||
|
// end for loop
|
||||||
|
}
|
||||||
|
if(verboseFlag)
|
||||||
|
{
|
||||||
|
printf("\nCourse Name: %s, Course Size: %d - recursion fell back to Recursion Level %d\n", tempCourse.courseName, tempCourse.size, roomLevel - 1);
|
||||||
|
printSpaces(2);
|
||||||
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
BIN
PA04-0927/build/Debug/outDebug
Executable file
BIN
PA04-0927/build/Debug/outDebug
Executable file
Binary file not shown.
Loading…
Add table
Add a link
Reference in a new issue