How to model that two teachers have to be assigned to an event?
How to model that two teachers have to be assigned to an event?
You can give an event two resources, one in the role "FirstTeacher", and the second one in the role "SecondTeacher". For these events you will have to specify twice the AssignResourceEvent (once for each role) and probably also twice the PreferResourcesConstraint. This last constraint requires also the role, but you can also specify the resource groups to choose the teacher from. Assigning the same teacher to both roles will lead to a clash (if the AvoidClashesConstraint is active for this teacher).
How to ensure that an event of duration 5 is split in two events of duration 2, and one event of duration 1?
How to ensure that an event of duration 5 is split in two events of duration 2, and one event of duration 1?
To do this you can use the SplitEventsConstraint for this event: you can specify the minimum duration (1), the maximum duration (2), the minimum amount (3) and the maximum amount (3). This forces the event to be split in 3 events in duration between 1 and 2, hence in two events of duration 2 and one event of duration 1.
I use the PreferTimesConstraint for an event, but I see no violation. How come?
I use the PreferTimesConstraint for an event, but I see no violation. How come?
Here you should be aware that the PreferTimesConstraint looks at the start time of an event, and not at all times occupied by the event. Read more ... So maybe the start time is in the set of preferred times, while the event (say of duration 2) runs into not preferred times. The PreferTimesConstraint will accept this as admissible. In such cases you can use the Duration attribute of the PreferTimesConstraint. You can keep the same constraint, but add Duration="1", and add a new PreferTimesConstraint with more restrictive times and Duration="2".
I have groups of room (special rooms) and some events need to get one room from this group assigned. How to model this?
I have groups of room (special rooms) and some events need to get one room from this group assigned. How to model this?
Assigning resources like rooms requires 3 steps.
  • You have to add an (empty) resource to the events that need a room from this group, specifying the role and type:
    <Resource>
       <Role>SpecialRoom</Role>
       <ResourceType Reference="Room"/>
    </Resource>

  • You should express that role Room should get a resource:
    <AssignResourceConstraint Id="AssignResourcesSpecialRooms">
        <Name>AssignResourcesSpecialRooms</Name>
        <Required>true</Required>
        <Weight>1</Weight>
        <CostFunction>Sum</CostFunction>
        <AppliesTo>
          <EventGroups>
               <EventGroup Reference="gr_AllEvents"/>
           </EventGroups>
        </AppliesTo>
        <Role>SpecialRoom</Role>
     </AssignResourceConstraint>

    N.B. Events which do not have the role "SpecialRoom" are ignored by the constraint.

  • You should express that you prefer a room from the special group:

    <PreferResourcesConstraint Id="PreferredResourcesSpecialRooms">
        <Name>PreferredResourcesSpecialRooms</Name>
        <Required>true</Required>
        <Weight>1</Weight>
        <CostFunction>Sum</CostFunction>
        <AppliesTo>
           <EventGroups>
              <EventGroup Reference="gr_AllEvents"/>
           </EventGroups>
        </AppliesTo>
        <ResourceGroups>
           <ResourceGroup Reference="gr_Rooms_Special"/>
        </ResourceGroups>
        <Role>SpecialRoom</Role>
     </PreferResourcesConstraint>

I have a class ("1") that for some events is split in two subgroups ("1A" and "1B"). How can I model this in XHSTT?
I have a class ("1") that for some events is split in two subgroups ("1A" and "1B"). How can I model this in XHSTT?
The easiest way is to introduce two resources "1A" and "1B", and one resource group "1", with members "1A" and "1B". For events with the full class add "1" as resource group, for events with one of the subgroups add "1A" or "1B" as resource. Probably the AvoidClassesConstraint is needed for the resources "1A" and "1B", or equivalently for the resource group "1". The last option is strictly equivalent, as adding the group means that it is valid for all members in the group.
Teacher A wants her lessons on 3 days. How can I model this in XHSTT?
Teacher A wants her lessons on 3 days. How can I model this in XHSTT?
The ClusterBusyTimesConstraint is meant for this situation. This constraint expresses that the number of time groups in which teacher A is busy should lie between the minimum (3) and the maximum (3). Below it is modeled as a soft constraint with weight 100. Note that this constraint does not express how many times the resource should be busy in these time groups. Such modeling can be done with the LimitBusyTimesConstraint, which has exactly the same syntax; see also the next question.

<ClusterBusyTimesConstraint Id="ThreeDaysForA">
    <Name>Lessons on 3 days for teacher A</Name>
    <Required>false</Required>
    <Weight>100</Weight>
    <CostFunction>SumSquare</CostFunction>
    <AppliesTo>
       <Resources>
          <Resource Reference="Teacher_A"/>
       </Resources>
    </AppliesTo>
    <TimeGroups>
       < TimeGroup Reference=" Day_mo "/>
       < TimeGroup Reference=" Day_tu "/>
       < TimeGroup Reference=" Day_we "/>
       < TimeGroup Reference=" Day_th "/>
       < TimeGroup Reference=" Day_fr "/>
    </TimeGroups>
    <Minimum>3</Minimum>
    <Maximum>3</Maximum>
 </ClusterBusyTimesConstraint >
Teacher B wants 3 to 5 busy times on her teaching days. How can I model this in XHSTT?
Teacher B wants 3 to 5 busy times on her teaching days. How can I model this in XHSTT?
The LimitBusyTimesConstraint is meant for this situation. This constraint expresses that if a resource is busy in one of the mentioned time groups, then the number of busy times should lie between the minimum and maximum.

<LimitBusyTimesConstraint Id="ThreeToFiveBusyTimesForB">
    <Name>3 to 5 busy times per day for B</Name>
    <Required>false</Required>
    <Weight>10</Weight>
    <CostFunction>SumSquare</CostFunction>
    <AppliesTo>
       <Resources>
          <Resource Reference="Teacher_B"/>
       </Resources>
    </AppliesTo>
    <TimeGroups>
       < TimeGroup Reference=" Day_mo "/>
       < TimeGroup Reference=" Day_tu "/>
       < TimeGroup Reference=" Day_we "/>
       < TimeGroup Reference=" Day_th "/>
       < TimeGroup Reference=" Day_fr "/>
    </TimeGroups>
    <Minimum>3</Minimum>
    <Maximum>5</Maximum>
 </LimitBusyTimesConstraint>
In our school classes can only be free of lessons on the last hour of the day. How to model this?
In our school classes can only be free of lessons on the last hour of the day. How to model this?
In XHSTT you will need two constraints for this: the first one expresses that classes have no idle times (i.e. free hours between lessons), and the second expresses that the classes should be busy on the first hour of the day. In XML this would look like:

<LimitIdleTimesConstraint Id="NoIdleTimesForClasses">
   <Name>No idle times for classes</Name>
   <Required>true</Required>
   <Weight>1</Weight>
   <CostFunction>Sum</CostFunction>
   <AppliesTo>
      <ResourceGroups>
         <ResourceGroup Reference="gr_Classes"/>
      </ResourceGroups>
   </AppliesTo>
   <TimeGroups>
      <TimeGroup Reference="gr_Mo"/>
      <TimeGroup Reference="gr_Tu"/>
      <TimeGroup Reference="gr_We"/>
      <TimeGroup Reference="gr_Th"/>
      <TimeGroup Reference="gr_Fr"/>
   </TimeGroups>
   <Minimum>0</Minimum>
   <Maximum>0</Maximum>
</LimitIdleTimesConstraint>


and

<LimitBusyTimesConstraint Id="ClasseBusyAtFirstHours">
   <Name>Busy all first hours</Name>
   <Required>true</Required>
   <Weight>1</Weight>
   <CostFunction>Sum</CostFunction>
   <AppliesTo>
      <ResourceGroups>
         <ResourceGroup Reference="gr_Classes"/>
      </ResourceGroups>
   </AppliesTo>
   <TimeGroups>
      <TimeGroup Reference="gr_FirstHoursOfDays"/>
   </TimeGroups>
   <Minimum>5</Minimum>
   <Maximum>5</Maximum>
</LimitBusyTimesConstraint>
In our school classes the lessons of a subject for a class should not be on consecutive days. How to model this?
In our school classes the lessons of a subject for a class should not be on consecutive days. How to model this?
The SpreadEventsConstraint can be used in this situation. Suppose the class has Id 3A, and the lessons to spread belong to courses (or event groups) with Ids gr_MATH_3A, gr_BIO_3A, and gr_GEO_3A. Next we need 4 time groups (if the lessons are on Monday to Friday), namely gr_MoTu, gr_TuWe, gr_WeTh, and gr_ThFr. Then the XML could look like:

<SpreadEventsConstraint Id="AtMostOneLessonOnConsecutiveDaysConstraint">
    <Name>One day between lessons</Name>
    <Required>true</Required>
    <Weight>1</Weight>
    <CostFunction>Sum</CostFunction>
    <AppliesTo>
       <EventGroups>
          <EventGroup Reference="gr_MATH_3A"/>
          <EventGroup Reference="gr_BIO_3A"/>
          <EventGroup Reference="gr_GEO_3A"/>
       </EventGroups>
    </AppliesTo>
    <TimeGroups>
       < TimeGroup Reference="gr_MoTu">
         <Minimum>0</Minimum>
         <Maximum>1</Maximum>
       </TimeGroup >
       < TimeGroup Reference="gr_TuWe">
         <Minimum>0</Minimum>
         <Maximum>1</Maximum>
       </TimeGroup >
       < TimeGroup Reference="gr_WeTh">
         <Minimum>0</Minimum>
         <Maximum>1</Maximum>
       </TimeGroup >
       < TimeGroup Reference="gr_ThFr">
         <Minimum>0</Minimum>
         <Maximum>1</Maximum>
       </TimeGroup >
    </TimeGroups>
 </SpreadEventsConstraint>