简体   繁体   中英

Implementing Conflict Graph Java

I am trying to create a program that decides whether or not a set of courses have conflicting times, and from those that do not, create the largest subset of courses. My idea is to create a graph with nodes being the courses and edges connecting the nodes being conflicts. I would then color each node with no two adjacent nodes having the same color. Then I would pick the subset of courses as the ones with the most frequent color. I know there are many different ways to represent graphs in Java, however, I have never created one before, and am wondering what approaches would be good to use in my case. OR would there a more efficient approach to this problem?

class Course {
    double startTime, endTime; //24-hour times
    String color;
    LinkedList<Course> conflictingCourses;

    boolean conflictsWith(Course otherCourse) {
        if (this.startTime > otherCourse.endTime || otherCourse.startTime > this.endTime)
            return false;
        return true;
    }
}

Go through all pairs of courses and see which pairs return true for conflictsWith. Then color them.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM