sukrutrao / Timetabler

A customizable timetabling software for educational institutions that encodes timetabling constraints as a SAT formula and solves them using a MaxSAT solver
https://timetabler.readthedocs.io
MIT License
38 stars 9 forks source link

I want 3 values for IsMinor ie. Yes, No, Lab #5

Closed Siddiq200 closed 6 years ago

Siddiq200 commented 6 years ago

I want 3 values for IsMinor ie. Yes, No, Lab ? Can you give me some guidence for this ?

I have changed

Minor.h:

enum MinorType {
    /**
     * Value when the Course is a minor course
     */
    isMinorCourse,
    /**
     * Value when the Course is not a minor course
     */
    isNotMinorCourse,
    /**
     * Value when the Course is not a minor course
     */
    isLabCourse
};

Parsing Input:

std::string isMinorStr = parser[i]["is_minor"];
        int isMinor;
        if (isMinorStr == "Yes") {
            isMinor = 0;
            assignmentsThisCourse[FieldType::isMinor].push_back(l_True);
        } else if (isMinorStr == "No") {
            isMinor = 1;
            assignmentsThisCourse[FieldType::isMinor].push_back(l_False);
        } else if(isMinorStr == "Lab"){
            isMinor = 2;
            assignmentsThisCourse[FieldType::isMinor].push_back(l_False);
        }else{
            std::cout << "Input contains invalid IsMinor value (should be 'Yes' , 'No' or 'Lab')" << std::endl;
            exit(1);
        }

Parsing YML:

 IsMinor isMinor = MinorType::isNotMinorCourse;
        std::string isMinorString = slotNode["is_minor"].as<std::string>();
        if(isMinorString == "true"){
            isMinor = MinorType::isMinorCourse;
        }else if(isMinorString == "false") {
            isMinor = MinorType::isNotMinorCourse;
        }else if(isMinorString == "lab"){
            isMinor = MinorType::isLabCourse;
        }

Parser line 67:

timeTabler->data.isMinors.push_back(IsMinor(MinorType::isMinorCourse));
    timeTabler->data.isMinors.push_back(IsMinor(MinorType::isNotMinorCourse));
    timeTabler->data.isMinors.push_back(IsMinor(MinorType::isLabCourse));

ConstraintAdder:


Clauses ConstraintAdder::minorInMinorTime() {
    Clauses result;
    result.clear();
    std::vector<Course> courses = timeTabler->data.courses;
    for(int i = 0; i < courses.size(); i++) {
        /*
         * a minor course must be in a minor Slot.
         * a non-minor course must not be in a minor Slot.
         */
        if(courses[i].getIsMinor() == 2){
            Clauses antecedent1 = encoder->isLabCourse(i);
            Clauses consequent1 = encoder->slotInLabTime(i);
            result.addClauses(antecedent1>>consequent1);
            result.addClauses(consequent1>>antecedent1);
        }else{
            Clauses antecedent = encoder->isMinorCourse(i);
            Clauses consequent = encoder->slotInMinorTime(i);
            result.addClauses(antecedent>>consequent);
            result.addClauses(consequent>>antecedent);}

    }
    return result;
}

```Please Guide me what else should I do.
Siddiq200 commented 6 years ago

And I did not understand this line ?

assignmentsThisCourse[FieldType::isMinor].push_back(l_False);

I have worked on Java I am New to C++ and OpenWBO

sukrutrao commented 6 years ago

Changes:

The above should probably be sufficient. If Lab and Minor are independent of each other (i.e., if a course can be both), you could alternatively add a new field for is_lab, and copy code from is_minor.

Siddiq200 commented 6 years ago

With the Above changes, adding two variables as you suggested in point 2 worked for me.... Thanks a lot.

As you mention in 3rd point I Remove If-Else to avoid any unexpected behaviour.

As you assume I have already defined isLabCourse() and slotInLabTime() similar to the existing functions for minor.

Now I can use 3 values for isMinor :)

Thanks for making Repository public. Thanks for Help.