Skip to content

Commit 5bb9bf5

Browse files
Merge pull request #760 from SidhantDash/main
Removed Dummy Data from Main and Updated New Features from Dev
2 parents 850879c + c065dce commit 5bb9bf5

98 files changed

Lines changed: 7666 additions & 2552 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.github/workflows/frontend.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,11 @@ on:
88

99
jobs:
1010
build:
11-
runs-on: ubuntu-20.04
11+
runs-on: ubuntu-24.04
1212
defaults:
1313
run:
1414
working-directory: ./frontend
15+
1516
name: Build and lint
1617
steps:
1718
- name: Checkout repository

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,3 +23,4 @@ node_modules/
2323
# Environment variables
2424
.env
2525
.env.*
26+

algorithm-prototyping/brute-force-prototype/src/main/java/edu/uga/devdogs/bruteforceprototype/BruteForcePrototype.java

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
import edu.uga.devdogs.sampledataparser.records.SConstraints;
88
import edu.uga.devdogs.sampledataparser.records.Section;
99

10-
import java.sql.Array;
1110
import java.util.*;
1211

1312
public class BruteForcePrototype {
@@ -42,9 +41,6 @@ public static int[][] algorithmDriver(Set<Course> inputCourses, Map<String, Map<
4241
return optimize(outputCourses, distances, softConstraints,false);
4342
} catch (Exception e){
4443
// If an exception arises from dataPreSoftFilter, we will call an overloaded version of optimize().
45-
// The overloaded version is not written yet, so when it is actually implemented,
46-
// this catch block will need updated accordingly.
47-
System.out.println(e.getMessage());
4844
//outputCourses = BruteForceUtil.dayOfWeekConvert(outputCourses);
4945
return optimize(outputCourses, distances, softConstraints, true);
5046
}
@@ -76,7 +72,7 @@ public static int[][] optimize(Set<Course> inputCourses, Map<String, Map<String,
7672
List<Schedule> sortedSchedules = new ArrayList<>();
7773
List<Double> sortedOverallObjectives = new ArrayList<>();
7874

79-
75+
8076
// Makeshift Priority Queue; An array sorted by a variable (in this case, overallObjective).
8177
// Before an item is added, you find where it should be placed so that the List is still sorted correctly
8278
// Without having to call a special sorting function.
@@ -167,8 +163,8 @@ private static void generateValidSchedulesRecursive(Set<Section> sections, List<
167163
// Instantiates the set of sections for the next iteration
168164
HashSet<Section> nextSections = new HashSet<>(sections);
169165
nextSections.add(sectionToAdd);
170-
166+
171167
generateValidSchedulesRecursive(nextSections, nextCoursesToAdd, validSchedules);
172168
}
173169
}
174-
}
170+
}

algorithm-prototyping/brute-force-prototype/src/main/java/edu/uga/devdogs/bruteforceprototype/BruteForceUtil.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import edu.uga.devdogs.sampledataparser.records.*;
44
import edu.uga.devdogs.sampledataparser.records.Class;
5+
import edu.uga.devdogs.bruteforceprototype.schedule.Schedule;
56

67
import java.time.DayOfWeek;
78
import java.util.ArrayList;
@@ -157,8 +158,9 @@ public static DayOfWeek daySwitch(String day) {
157158
*
158159
* @param inputCourses user inputted courses.
159160
* @param validSchedules a set of valid generated schedules
161+
* @throws Exception if {@code courseInSchedule} if true
160162
*/
161-
public static void ensureInitialCourses(Set<Course> inputCourses, Set<Schedules> validSchedules) {
163+
public static void ensureInitialCourses(Set<Course> inputCourses, Set<Schedule> validSchedules) throws Exception {
162164
boolean courseInSchedule = false;
163165
// for every user inputted course
164166
for (Course c : inputCourses) {
@@ -167,12 +169,12 @@ public static void ensureInitialCourses(Set<Course> inputCourses, Set<Schedules>
167169
// for every section in said schedule
168170
for (Section sect : s.sections()) {
169171
// if the course the user inputted, c, is in the schedule, s
170-
if (c.courseCode == sect.courseCode) {
172+
if (c.courseCode().equals(sect.courseCode())) {
171173
courseInSchedule = true;
172174
} // if
173175
} // for
174176
if (!courseInSchedule) {
175-
throw new Exception("Schedule does not contain specified course.")
177+
throw new Exception("Schedule does not contain specified course.");
176178
} // if
177179
} // for
178180
} // for

algorithm-prototyping/brute-force-prototype/src/main/java/edu/uga/devdogs/bruteforceprototype/schedule/Schedule.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,5 +65,4 @@ public Set<Section> sections() {
6565
public EnumMap<DayOfWeek, TreeSet<Class>> days() {
6666
return days;
6767
}
68-
}
69-
68+
}

algorithm-prototyping/brute-force-prototype/src/main/java/edu/uga/devdogs/bruteforceprototype/schedule/ScheduleUtil.java

Lines changed: 103 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,20 @@
55
import edu.uga.devdogs.sampledataparser.records.Class;
66
import edu.uga.devdogs.sampledataparser.records.HConstraints;
77

8+
//import edu.uga.devdogs.course_information.service;
9+
//import org.springframework.beans.factory.annotation.Autowired;
10+
811
import java.util.ArrayList;
912
import java.util.List;
1013
import java.util.Map;
1114
import java.util.TreeSet;
15+
import java.util.EnumMap;
1216
import java.util.Set;
1317

18+
import java.time.DayOfWeek;
19+
import java.time.LocalTime;
20+
21+
1422

1523
/**
1624
* Utility class for performing operations and calculations related to a Schedule.
@@ -22,6 +30,10 @@
2230
*/
2331
public class ScheduleUtil {
2432

33+
// Used for bootstrap getting coords
34+
//@Autowired
35+
//private CourseInformationService courseInformationService;
36+
2537
/**
2638
* Validates the given schedule by checking for any time conflicts between classes.
2739
* A time conflict occurs when two classes overlap in their scheduled times.
@@ -86,7 +98,7 @@ public static double computeAverageProfessorQuality(Schedule schedule) {
8698

8799
/**
88100
* Checks if schedule or constraints is null and throws an exception if it is.
89-
*
101+
*
90102
* @param schedule the schedule to validate
91103
* @param constraints the constraints to validate
92104
*/
@@ -115,22 +127,46 @@ public static double computeMaxDistance(Schedule schedule, Map<String, Map<Strin
115127
// Iterates over each day in the schedule
116128
for (TreeSet<Class> day : schedule.days().values()) {
117129
// Converts the TreeSet to List for direct indexing
118-
// TODO: Replace TreeSet with a sorted List for days in Schedule
119130
List<Class> dayList = new ArrayList<>(day);
120131

121132
// Iterates over consecutive class pairs
122133
for (int i = 0; i < dayList.size() - 1; i++) {
123134
Class currClass = dayList.get(i);
124135
Class nextClass = dayList.get(i + 1);
125-
double distance = distances.get(currClass.buildingName()).get(nextClass.buildingName());
136+
137+
double lat1 = 0.0;//courseInformationService.getLatitude(currClass.buildingNumber());
138+
double lon1 = 0.0; //courseInformationService.getLongitude(currClass.buildingNumber());
139+
double lon2 = 0.0; //courseInformationService.getLongitude(nextClass.buildingNumber());
140+
double lat2 = 0.0; //courseInformationService.getLatitude(nextClass.buildingNumber());
141+
142+
// distance between latitudes and longitudes
143+
double dLat = Math.toRadians(lat2 - lat1);
144+
double dLon = Math.toRadians(lon2 - lon1);
145+
146+
// convert to radians
147+
lat1 = Math.toRadians(lat1);
148+
lat2 = Math.toRadians(lat2);
149+
150+
// apply Haversine formula
151+
double a = Math.pow(Math.sin(dLat / 2), 2) +
152+
Math.pow(Math.sin(dLon / 2), 2) *
153+
Math.cos(lat1) *
154+
Math.cos(lat2);
155+
156+
// Earth's radius in miles
157+
double rad = 3960;
158+
double c = 2 * Math.asin(Math.sqrt(a));
159+
double distance = rad * c;
126160

127161
if (distance > maxDistance) {
128162
maxDistance = distance;
129163
}
130164
}
131165
}
132166

133-
return maxDistance;
167+
// dimensional analysis. Average human walking speed is 3 miles per hour.
168+
// miles * (hours/miles) * (minutes/hours)
169+
return maxDistance * (1/3) * (60);
134170
}
135171

136172
/**
@@ -174,6 +210,63 @@ public static double computeAverageIdleTime(Schedule schedule) {
174210
return (double) sumOfTimeGaps / countOfClassGaps;
175211
}
176212

213+
214+
215+
/**
216+
* Computes the earliest start time of all classes in a schedule
217+
*
218+
* @param schedule the schedule for which to compute the earliest start time
219+
* @return the earliest start time (in hours) as a double. For example, 4:30 pm would be represented as 16.5
220+
*/
221+
public static double computeStartTime(Schedule schedule) {
222+
LocalTime earliestStartTime = LocalTime.of(23,59,59);
223+
for (Section eachSection : schedule.sections()) {
224+
for (Class eachClass : eachSection.classes()) {
225+
if (eachClass.startTime().isBefore(earliestStartTime)) {
226+
earliestStartTime = eachClass.startTime();
227+
}
228+
}
229+
}
230+
return earliestStartTime.getHour() + (double) earliestStartTime.getMinute() / 60;
231+
}
232+
233+
234+
235+
/**
236+
* Computes the latest start time of all classes in a schedule
237+
*
238+
* @param schedule the schedule for which to compute the latest start time
239+
* @return the latest start time (in hours) as a double. For example, 4:30 pm would be represented as 16.5
240+
*/
241+
private static double computeEndTime(Schedule schedule) {
242+
LocalTime latestStartTime = LocalTime.of(0,0,0);
243+
for (Section eachSection : schedule.sections()) {
244+
for (Class eachClass : eachSection.classes()) {
245+
if (eachClass.startTime().isAfter(latestStartTime)) {
246+
latestStartTime = eachClass.startTime();
247+
}
248+
}
249+
}
250+
return latestStartTime.getHour() + (double) latestStartTime.getMinute() / 60;
251+
}
252+
253+
254+
255+
/**
256+
* Determines whether a given schedule has zero classes on a given day
257+
*
258+
* @param schedule the schedule for which to compute whether it has a gap day or not
259+
* @param gapDay the day that is being checked as a gap day or not
260+
* @return {@code true} if the given schedule has no classes on the given day, {@code false} if it has at least one class
261+
*/
262+
private static boolean computeGapDay(Schedule schedule, DayOfWeek gapDay) {
263+
EnumMap<DayOfWeek, TreeSet<Class>> days = schedule.days();
264+
TreeSet<Class> classes = days.get(gapDay);
265+
return classes.isEmpty();
266+
}
267+
268+
269+
177270
/**
178271
* Computes the overall objective score for the given schedule based on weighted objectives.
179272
* This method computes each objective, normalizes their values using min-max normalization, and computes a weighted sum.
@@ -185,10 +278,10 @@ public static double computeAverageIdleTime(Schedule schedule) {
185278
* @return the overall objective score for the schedule
186279
*/
187280
public static double computeOverallObjective(Schedule schedule, Map<String, Map<String, Double>> distances) {
188-
// Checks if the parameters are valid
189-
if (schedule == null || distances == null) {
190-
throw new IllegalArgumentException("Parameters cannot be null");
191-
}
281+
// Checks if the parameters are valid
282+
if (schedule == null || distances == null) {
283+
throw new IllegalArgumentException("Parameters cannot be null");
284+
}
192285

193286
// The minimum rating on rate my professor is 1.0(if they have ratings).
194287
final double professorQualityMinimum = 1.0;
@@ -251,7 +344,7 @@ public static double computeOverallObjectiveExtended(Schedule schedule, Map<Stri
251344
possSConstraintsCount++;
252345
}
253346
if (softConstraints.prefStartTime() != null) {
254-
possSConstraintScore += normalizeValue(computeStartTime(schedule), prefTimeMinimum, prefTimeMaximum);;
347+
possSConstraintScore += normalizeValue(computeStartTime(schedule), prefTimeMinimum, prefTimeMaximum);
255348
possSConstraintsCount++;
256349
}
257350
if (softConstraints.prefEndTime() != null) {
@@ -310,4 +403,4 @@ public static int[] sectionsToInts(Set<Section> sections) {
310403
return output;
311404
}
312405

313-
}
406+
}
430 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)