<commit_before>/*
 * Licensed to The Apereo Foundation under one or more contributor license
 * agreements. See the NOTICE file distributed with this work for
 * additional information regarding copyright ownership.
 *
 * The Apereo Foundation licenses this file to you under the Apache License,
 * Version 2.0 (the "License"); you may not use this file except in
 * compliance with the License. You may obtain a copy of the License at:
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * 
*/
package org.unitime.timetable.solver.exam.ui;

import java.io.Serializable;
import java.util.Collection;
import java.util.Date;
import java.util.Hashtable;
import java.util.Iterator;
import java.util.Set;
import java.util.StringTokenizer;
import java.util.TreeSet;
import java.util.Vector;

import org.cpsolver.coursett.preference.MinMaxPreferenceCombination;
import org.cpsolver.exam.criteria.ExamRotationPenalty;
import org.cpsolver.exam.criteria.InstructorBackToBackConflicts;
import org.cpsolver.exam.criteria.InstructorDirectConflicts;
import org.cpsolver.exam.criteria.InstructorDistanceBackToBackConflicts;
import org.cpsolver.exam.criteria.InstructorMoreThan2ADayConflicts;
import org.cpsolver.exam.criteria.InstructorNotAvailableConflicts;
import org.cpsolver.exam.criteria.PeriodPenalty;
import org.cpsolver.exam.criteria.RoomPenalty;
import org.cpsolver.exam.criteria.RoomSizePenalty;
import org.cpsolver.exam.criteria.RoomSplitPenalty;
import org.cpsolver.exam.criteria.StudentBackToBackConflicts;
import org.cpsolver.exam.criteria.StudentDistanceBackToBackConflicts;
import org.cpsolver.exam.criteria.StudentMoreThan2ADayConflicts;
import org.cpsolver.exam.criteria.StudentNotAvailableConflicts;
import org.cpsolver.exam.model.ExamDistributionConstraint;
import org.cpsolver.exam.model.ExamPlacement;
import org.cpsolver.exam.model.ExamRoomPlacement;
import org.cpsolver.ifs.assignment.Assignment;
import org.cpsolver.ifs.util.ToolBox;
import org.unitime.localization.impl.Localization;
import org.unitime.timetable.defaults.ApplicationProperty;
import org.unitime.timetable.gwt.resources.GwtConstants;
import org.unitime.timetable.model.Exam;
import org.unitime.timetable.model.ExamPeriod;
import org.unitime.timetable.model.ExamPeriodPref;
import org.unitime.timetable.model.ExamType;
import org.unitime.timetable.model.Location;
import org.unitime.timetable.model.PreferenceLevel;
import org.unitime.timetable.model.dao.ExamPeriodDAO;
import org.unitime.timetable.util.Constants;
import org.unitime.timetable.util.Formats;
import org.unitime.timetable.util.Formats.Format;


/**
 * @author <NAME>
 */
public class ExamAssignment extends ExamInfo implements Serializable {
	private static final long serialVersionUID = -5726339642542287195L;
	protected static GwtConstants CONSTANTS = Localization.create(GwtConstants.class);
    private Format<Number> s2Z = Formats.getNumberFormat("00");
    private Format<Date> sDateFormat = Formats.getDateFormat(Formats.Pattern.DATE_EXAM_PERIOD);
    protected Long iPeriodId = null;
    protected TreeSet<ExamRoomInfo> iRooms = null;
    protected String iPeriodPref = null;
    protected int iPeriodIdx = -1;
    protected transient ExamPeriod iPeriod = null;
    protected ExamInfo iExam = null;
    protected String iDistPref = null;
    
    protected int iNrDirectConflicts = 0;
    protected int iNrMoreThanTwoADayConflicts = 0;
    protected int iNrBackToBackConflicts = 0;
    protected int iNrDistanceBackToBackConflicts = 0;
    protected int iPeriodPenalty = 0;
    protected int iRoomSizePenalty = 0;
    protected int iRoomSplitPenalty = 0;
    protected int iRotationPenalty = 0;
    protected int iRoomPenalty = 0;
    protected int iNrInstructorDirectConflicts = 0;
    protected int iNrInstructorMoreThanTwoADayConflicts = 0;
    protected int iNrInstructorBackToBackConflicts = 0;
    protected int iNrInstructorDistanceBackToBackConflicts = 0;
    protected double iValue = 0;
    
    public ExamAssignment(ExamPlacement placement, Assignment<org.cpsolver.exam.model.Exam, ExamPlacement> assignment) {
        this((org.cpsolver.exam.model.Exam)placement.variable(), placement, assignment);
    }
    
    public ExamAssignment(org.cpsolver.exam.model.Exam exam, ExamPlacement placement, Assignment<org.cpsolver.exam.model.Exam, ExamPlacement> assignment) {
        super(exam);
        if (placement!=null) {
            iNrDirectConflicts = (int)exam.getModel().getCriterion(StudentDistanceBackToBackConflicts.class).getValue(assignment, placement, null) +
            					 (int)exam.getModel().getCriterion(StudentNotAvailableConflicts.class).getValue(assignment, placement, null);
            iNrMoreThanTwoADayConflicts = (int)exam.getModel().getCriterion(StudentMoreThan2ADayConflicts.class).getValue(assignment, placement, null);
            iNrBackToBackConflicts = (int)exam.getModel().getCriterion(StudentBackToBackConflicts.class).getValue(assignment, placement, null);
            iNrDistanceBackToBackConflicts = (int)exam.getModel().getCriterion(StudentDistanceBackToBackConflicts.class).getValue(assignment, placement, null);
            iPeriodPenalty = (int)exam.getModel().getCriterion(PeriodPenalty.class).getValue(assignment, placement, null);
            iRoomSizePenalty = (int)exam.getModel().getCriterion(RoomSizePenalty.class).getValue(assignment, placement, null);
            iRoomSplitPenalty = (int)exam.getModel().getCriterion(RoomSplitPenalty.class).getValue(assignment, placement, null);
            iRotationPenalty = (int)exam.getModel().getCriterion(ExamRotationPenalty.class).getValue(assignment, placement, null);
            iRoomPenalty = (int)exam.getModel().getCriterion(RoomPenalty.class).getValue(assignment, placement, null);
            iNrInstructorDirectConflicts = (int)exam.getModel().getCriterion(InstructorDirectConflicts.class).getValue(assignment, placement, null) +
            		(int)exam.getModel().getCriterion(InstructorNotAvailableConflicts.class).getValue(assignment, placement, null);
            iNrInstructorMoreThanTwoADayConflicts = (int)exam.getModel().getCriterion(InstructorMoreThan2ADayConflicts.class).getValue(assignment, placement, null);
            iNrInstructorBackToBackConflicts = (int)exam.getModel().getCriterion(InstructorBackToBackConflicts.class).getValue(assignment, placement, null);
            iNrInstructorDistanceBackToBackConflicts = (int)exam.getModel().getCriterion(InstructorDistanceBackToBackConflicts.class).getValue(assignment, placement, null);
            iValue = placement.toDouble(assignment);
            iPeriodId = placement.getPeriod().getId();
            iPeriodIdx = placement.getPeriod().getIndex();
            iRooms = new TreeSet<ExamRoomInfo>();
            iPeriodPref = (exam.getPeriodPlacements().size()==1?PreferenceLevel.sRequired:PreferenceLevel.int2prolog(iPeriodPenalty));
            if (placement.getRoomPlacements()!=null) {
                boolean reqRoom = placement.getRoomPlacements().size()==exam.getRoomPlacements().size();
                for (Iterator i=placement.getRoomPlacements().iterator();i.hasNext();) {
                    ExamRoomPlacement room = (ExamRoomPlacement)i.next();<commit_msg>Examination Assignment: direct conflict counts<commit_after>/*
 * Licensed to The Apereo Foundation under one or more contributor license
 * agreements. See the NOTICE file distributed with this work for
 * additional information regarding copyright ownership.
 *
 * The Apereo Foundation licenses this file to you under the Apache License,
 * Version 2.0 (the "License"); you may not use this file except in
 * compliance with the License. You may obtain a copy of the License at:
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * 
*/
package org.unitime.timetable.solver.exam.ui;

import java.io.Serializable;
import java.util.Collection;
import java.util.Date;
import java.util.Hashtable;
import java.util.Iterator;
import java.util.Set;
import java.util.StringTokenizer;
import java.util.TreeSet;
import java.util.Vector;

import org.cpsolver.coursett.preference.MinMaxPreferenceCombination;
import org.cpsolver.exam.criteria.ExamRotationPenalty;
import org.cpsolver.exam.criteria.InstructorBackToBackConflicts;
import org.cpsolver.exam.criteria.InstructorDirectConflicts;
import org.cpsolver.exam.criteria.InstructorDistanceBackToBackConflicts;
import org.cpsolver.exam.criteria.InstructorMoreThan2ADayConflicts;
import org.cpsolver.exam.criteria.InstructorNotAvailableConflicts;
import org.cpsolver.exam.criteria.PeriodPenalty;
import org.cpsolver.exam.criteria.RoomPenalty;
import org.cpsolver.exam.criteria.RoomSizePenalty;
import org.cpsolver.exam.criteria.RoomSplitPenalty;
import org.cpsolver.exam.criteria.StudentBackToBackConflicts;
import org.cpsolver.exam.criteria.StudentDirectConflicts;
import org.cpsolver.exam.criteria.StudentDistanceBackToBackConflicts;
import org.cpsolver.exam.criteria.StudentMoreThan2ADayConflicts;
import org.cpsolver.exam.criteria.StudentNotAvailableConflicts;
import org.cpsolver.exam.model.ExamDistributionConstraint;
import org.cpsolver.exam.model.ExamPlacement;
import org.cpsolver.exam.model.ExamRoomPlacement;
import org.cpsolver.ifs.assignment.Assignment;
import org.cpsolver.ifs.util.ToolBox;
import org.unitime.localization.impl.Localization;
import org.unitime.timetable.defaults.ApplicationProperty;
import org.unitime.timetable.gwt.resources.GwtConstants;
import org.unitime.timetable.model.Exam;
import org.unitime.timetable.model.ExamPeriod;
import org.unitime.timetable.model.ExamPeriodPref;
import org.unitime.timetable.model.ExamType;
import org.unitime.timetable.model.Location;
import org.unitime.timetable.model.PreferenceLevel;
import org.unitime.timetable.model.dao.ExamPeriodDAO;
import org.unitime.timetable.util.Constants;
import org.unitime.timetable.util.Formats;
import org.unitime.timetable.util.Formats.Format;


/**
 * @author <NAME>
 */
public class ExamAssignment extends ExamInfo implements Serializable {
	private static final long serialVersionUID = -5726339642542287195L;
	protected static GwtConstants CONSTANTS = Localization.create(GwtConstants.class);
    private Format<Number> s2Z = Formats.getNumberFormat("00");
    private Format<Date> sDateFormat = Formats.getDateFormat(Formats.Pattern.DATE_EXAM_PERIOD);
    protected Long iPeriodId = null;
    protected TreeSet<ExamRoomInfo> iRooms = null;
    protected String iPeriodPref = null;
    protected int iPeriodIdx = -1;
    protected transient ExamPeriod iPeriod = null;
    protected ExamInfo iExam = null;
    protected String iDistPref = null;
    
    protected int iNrDirectConflicts = 0;
    protected int iNrMoreThanTwoADayConflicts = 0;
    protected int iNrBackToBackConflicts = 0;
    protected int iNrDistanceBackToBackConflicts = 0;
    protected int iPeriodPenalty = 0;
    protected int iRoomSizePenalty = 0;
    protected int iRoomSplitPenalty = 0;
    protected int iRotationPenalty = 0;
    protected int iRoomPenalty = 0;
    protected int iNrInstructorDirectConflicts = 0;
    protected int iNrInstructorMoreThanTwoADayConflicts = 0;
    protected int iNrInstructorBackToBackConflicts = 0;
    protected int iNrInstructorDistanceBackToBackConflicts = 0;
    protected double iValue = 0;
    
    public ExamAssignment(ExamPlacement placement, Assignment<org.cpsolver.exam.model.Exam, ExamPlacement> assignment) {
        this((org.cpsolver.exam.model.Exam)placement.variable(), placement, assignment);
    }
    
    public ExamAssignment(org.cpsolver.exam.model.Exam exam, ExamPlacement placement, Assignment<org.cpsolver.exam.model.Exam, ExamPlacement> assignment) {
        super(exam);
        if (placement!=null) {
            iNrDirectConflicts = (int)exam.getModel().getCriterion(StudentDirectConflicts.class).getValue(assignment, placement, null) +
            					 (int)exam.getModel().getCriterion(StudentNotAvailableConflicts.class).getValue(assignment, placement, null);
            iNrMoreThanTwoADayConflicts = (int)exam.getModel().getCriterion(StudentMoreThan2ADayConflicts.class).getValue(assignment, placement, null);
            iNrBackToBackConflicts = (int)exam.getModel().getCriterion(StudentBackToBackConflicts.class).getValue(assignment, placement, null);
            iNrDistanceBackToBackConflicts = (int)exam.getModel().getCriterion(StudentDistanceBackToBackConflicts.class).getValue(assignment, placement, null);
            iPeriodPenalty = (int)exam.getModel().getCriterion(PeriodPenalty.class).getValue(assignment, placement, null);
            iRoomSizePenalty = (int)exam.getModel().getCriterion(RoomSizePenalty.class).getValue(assignment, placement, null);
            iRoomSplitPenalty = (int)exam.getModel().getCriterion(RoomSplitPenalty.class).getValue(assignment, placement, null);
            iRotationPenalty = (int)exam.getModel().getCriterion(ExamRotationPenalty.class).getValue(assignment, placement, null);
            iRoomPenalty = (int)exam.getModel().getCriterion(RoomPenalty.class).getValue(assignment, placement, null);
            iNrInstructorDirectConflicts = (int)exam.getModel().getCriterion(InstructorDirectConflicts.class).getValue(assignment, placement, null) +
            		(int)exam.getModel().getCriterion(InstructorNotAvailableConflicts.class).getValue(assignment, placement, null);
            iNrInstructorMoreThanTwoADayConflicts = (int)exam.getModel().getCriterion(InstructorMoreThan2ADayConflicts.class).getValue(assignment, placement, null);
            iNrInstructorBackToBackConflicts = (int)exam.getModel().getCriterion(InstructorBackToBackConflicts.class).getValue(assignment, placement, null);
            iNrInstructorDistanceBackToBackConflicts = (int)exam.getModel().getCriterion(InstructorDistanceBackToBackConflicts.class).getValue(assignment, placement, null);
            iValue = placement.toDouble(assignment);
            iPeriodId = placement.getPeriod().getId();
            iPeriodIdx = placement.getPeriod().getIndex();
            iRooms = new TreeSet<ExamRoomInfo>();
            iPeriodPref = (exam.getPeriodPlacements().size()==1?PreferenceLevel.sRequired:PreferenceLevel.int2prolog(iPeriodPenalty));
            if (placement.getRoomPlacements()!=null) {
                boolean reqRoom = placement.getRoomPlacements().size()==exam.getRoomPlacements().size();
                for (Iterator i=placement.getRoomPlacements().iterator();i.hasNext();) {
                    ExamRoomPlacement room = (ExamRoomPlacement)i.next();
{'fraction_non_alphanumeric': 0.09467768595041322, 'fraction_numerical': 0.006214876033057851, 'mean_word_length': 5.047980807676929, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 17, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2404672', 'n_tokens_mistral': 4667, 'n_tokens_neox': 4483, 'n_words': 827}