net.sf.cpsolver.coursett.constraint
Class FlexibleConstraint

java.lang.Object
  extended by net.sf.cpsolver.ifs.model.Constraint<Lecture,Placement>
      extended by net.sf.cpsolver.coursett.constraint.FlexibleConstraint
All Implemented Interfaces:
Comparable<Constraint<Lecture,Placement>>
Direct Known Subclasses:
BreakFlexibleConstraint, MaxBlockFlexibleConstraint, MaxBreaksFlexibleConstraint

public abstract class FlexibleConstraint
extends Constraint<Lecture,Placement>

Flexible constraint.
This constraint expresses relations between several classes. Provides similar functions as Group constraint. Unlike group constraint, Flexible constraint is able to parse some of its parameters from its reference field

Version:
CourseTT 1.2 (University Course Timetabling)
Copyright (C) 2013 Matej Lukac

This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 3 of the License, or (at your option) any later version.

This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.

You should have received a copy of the GNU Lesser General Public License along with this library; if not see http://www.gnu.org/licenses/.

Nested Class Summary
 class FlexibleConstraint.Block
          A block is a list of placements sorted by startSlot, which are BTB.
static class FlexibleConstraint.FlexibleConstraintType
          Flexible constraint types
protected static class FlexibleConstraint.PlacementTimeComparator
          Placement comparator: earlier placement first, shorter placement first if both start at the same time.
 
Field Summary
protected  FlexibleConstraint.FlexibleConstraintType iConstraintType
           
protected  String iReference
           
protected  List<BitSet> iWeeks
           
 
Fields inherited from class net.sf.cpsolver.ifs.model.Constraint
iAssignedVariables, iConstraintListeners, iId
 
Constructor Summary
FlexibleConstraint(Long id, String owner, String preference, String reference)
           
 
Method Summary
 void assigned(long iteration, Placement value)
          Given value is to be assigned to its varable.
abstract  void computeConflicts(Placement value, Set<Placement> conflicts)
          The only method which has to be implemented by any constraint.
 double getCurrentPreference(Set<Placement> conflicts, HashMap<Lecture,Placement> assignments)
          Return the current preference of the flexible constraint, considering conflicts and new assignments.
 String getName()
          Constraint's name -- for printing purposes
abstract  double getNrViolations(Set<Placement> conflicts, HashMap<Lecture,Placement> assignments)
           
 String getOwner()
           
 String getPrologPreference()
          Prolog reference: "R" for required, "P" for prohibited", "-2",.."2" for preference
 String getReference()
           
protected  Set<Placement> getRelevantPlacements(int dayCode, Set<Placement> conflicts, Placement value, HashMap<Lecture,Placement> assignments, BitSet week)
          Returns placements of variables assigned to this constraint with assignment which satisfy following conditions: They must be taught in the day included in dayCode.
 FlexibleConstraint.FlexibleConstraintType getType()
           
 List<BitSet> getWeeks()
           
 boolean isConsistent(Placement value1, Placement value2)
          Returns true if the given assignments are consistent respecting this constraint.
 boolean isHard()
          Returns true if the constraint is hard.
protected  List<FlexibleConstraint.Block> mergeToBlocks(List<Placement> sorted, int maxBreakBetweenBTB)
          Creates a list of blocks from a placements sorted by startSlot
 String toString()
           
 void unassigned(long iteration, Placement value)
          Given value is unassigned from its variable.
 
Methods inherited from class net.sf.cpsolver.ifs.model.Constraint
addConstraintListener, addVariable, assignedVariables, compareTo, constraintListeners, countAssignedVariables, countVariables, equals, getDescription, getId, getModel, hashCode, inConflict, removeConstraintListener, removeVariable, setModel, variables
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

iConstraintType

protected FlexibleConstraint.FlexibleConstraintType iConstraintType

iReference

protected String iReference

iWeeks

protected List<BitSet> iWeeks
Constructor Detail

FlexibleConstraint

public FlexibleConstraint(Long id,
                          String owner,
                          String preference,
                          String reference)
Parameters:
owner - identifier of distribution preference the constraint was created for
preference - time preference ("R" for required, "P" for prohibited, "-2", "-1", "1", "2" for soft preference)
reference - parameters of the constraint in String form
Method Detail

computeConflicts

public abstract void computeConflicts(Placement value,
                                      Set<Placement> conflicts)
Description copied from class: Constraint
The only method which has to be implemented by any constraint. It returns the values which needs to be unassigned in order to make this constraint consistent with the given value if it is assigned to its variable. The computed list of conflicting values is added to the given set of conflicts.

Specified by:
computeConflicts in class Constraint<Lecture,Placement>
Parameters:
value - value to be assigned to its varaible
conflicts - resultant set of conflicting values

getNrViolations

public abstract double getNrViolations(Set<Placement> conflicts,
                                       HashMap<Lecture,Placement> assignments)
Parameters:
conflicts - conflicting placements to be unassigned
assignments - assigned placements
Returns:
the number of violations of the constraint during days and all weeks of the semester

getWeeks

public List<BitSet> getWeeks()
Returns:
i list of bitsets representing datePatterns or null if semester is whole semester is considered

isConsistent

public boolean isConsistent(Placement value1,
                            Placement value2)
Description copied from class: Constraint
Returns true if the given assignments are consistent respecting this constraint. This method is used by MAC (see MacPropagation).

Overrides:
isConsistent in class Constraint<Lecture,Placement>

getRelevantPlacements

protected Set<Placement> getRelevantPlacements(int dayCode,
                                               Set<Placement> conflicts,
                                               Placement value,
                                               HashMap<Lecture,Placement> assignments,
                                               BitSet week)
Returns placements of variables assigned to this constraint with assignment which satisfy following conditions: They must be taught in the day included in dayCode. They cannot be included in conflicts Their date pattern intersects with week

Parameters:
dayCode - representation of days in week combination
conflicts - placements to be unassigned
value - placement to be assigned
assignments - placements of variables
week - bitset representing a date pattern
Returns:
placements of variables assigned to this constraint with assignment which satisfy conditions above

mergeToBlocks

protected List<FlexibleConstraint.Block> mergeToBlocks(List<Placement> sorted,
                                                       int maxBreakBetweenBTB)
Creates a list of blocks from a placements sorted by startSlot

Parameters:
sorted - list of placements sorted by startSlot
maxBreakBetweenBTB - maximum number of free slots between BTB placements
Returns:
groups of BTB placements as a list of blocks

isHard

public boolean isHard()
Description copied from class: Constraint
Returns true if the constraint is hard. Only hard constraints are allowed to unassign a variable when there is a conflict with a value that is being assigned

Overrides:
isHard in class Constraint<Lecture,Placement>

getName

public String getName()
Description copied from class: Constraint
Constraint's name -- for printing purposes

Overrides:
getName in class Constraint<Lecture,Placement>

getType

public FlexibleConstraint.FlexibleConstraintType getType()

assigned

public void assigned(long iteration,
                     Placement value)
Description copied from class: Constraint
Given value is to be assigned to its varable. In this method, the constraint should unassigns all varaibles which are in conflict with the given assignment because of this constraint.

Overrides:
assigned in class Constraint<Lecture,Placement>

getReference

public String getReference()

getOwner

public String getOwner()

getPrologPreference

public String getPrologPreference()
Prolog reference: "R" for required, "P" for prohibited", "-2",.."2" for preference


getCurrentPreference

public double getCurrentPreference(Set<Placement> conflicts,
                                   HashMap<Lecture,Placement> assignments)
Return the current preference of the flexible constraint, considering conflicts and new assignments. Used to compute value for flexible constraint criterion.

Parameters:
conflicts -
assignments -
Returns:
the current preference of the flexible constraint

unassigned

public void unassigned(long iteration,
                       Placement value)
Description copied from class: Constraint
Given value is unassigned from its variable.

Overrides:
unassigned in class Constraint<Lecture,Placement>

toString

public String toString()
Overrides:
toString in class Object


Copyright © 2014 UniTime LLC. All Rights Reserved.