public Constraint(Group g, Station s, int n)
 {
     G = g;
     S = s;
     nTimes = n;
 }
        private static bool isStationAvailableAtSlot(Station station, int dayNumber, int slotNumber)
        {
            if (station.Capacity == 0)
                return false;

            foreach (StationDay day in station.Availabilities)
            {
                if (day.DayNumber == dayNumber && day.OpenSlotNumbers.Contains((uint)slotNumber))
                    return true;
            }

            return false;
        }
        private static int score(Dictionary<int, int>[,] masterSchedule, Station S, Group G, int Day, int Slot)
        {
            int ret = 0;

            int i, j;

            // check if other constraints will be violated if this assignment happens.

            // station cap - 1 for the current assigmment
            int stationIndex = getStationIndex(S);
            int stationTotalAvailableSlotsLeft = S.totalAvailabltSlots - StationAssignmentsCounts[stationIndex] - 1;

            int otherGroupsNeedThisStation = 0;

            if (stationTotalAvailableSlotsLeft < 0)
                throw new Exception("Error generating schedule. SC-1");

            // look for anyone else who wants this station.
            for (i = 0; i < AllConstraints.Count; i++)
            {
                if (ConstraintMet[i] || AllConstraints[i].S != S || AllConstraints[i].G == G)
                    continue;

                otherGroupsNeedThisStation++;
            }

            if (otherGroupsNeedThisStation > stationTotalAvailableSlotsLeft)
            {
                ret += CONSTRAINT_PENALTY * (otherGroupsNeedThisStation - stationTotalAvailableSlotsLeft);
            }

            int nFirstPicks = 0;
            int nSecondPicks = 0;
            int nThirdPicks = 0;
            int nNoPicks = 0;

            // Check how many groups get their second pick instead of first, and how many groups aren't getting any picks

            // Copy the total assignment count for stations.
            int[] StationAssignmentsCountsTemp = (int[])StationAssignmentsCounts.Clone();
            StationAssignmentsCountsTemp[stationIndex]++;

            int stationPick1AvailableSlots, stationPick2AvailableSlots, stationPick3AvailableSlots;

            for (i = 0; i < AllGroups.Count; i++)
            {
                if( AllGroups[i].StationPick1 == -1 )
                    continue;

                stationPick1AvailableSlots = AllGroups[i].StationPick1 == -1 ? 0 : AllStations[AllGroups[i].StationPick1].totalAvailabltSlots - StationAssignmentsCountsTemp[AllGroups[i].StationPick1];
                stationPick2AvailableSlots = AllGroups[i].StationPick2 == -1 ? 0 : AllStations[AllGroups[i].StationPick2].totalAvailabltSlots - StationAssignmentsCountsTemp[AllGroups[i].StationPick2];
                stationPick3AvailableSlots = AllGroups[i].StationPick3 == -1 ? 0 : AllStations[AllGroups[i].StationPick3].totalAvailabltSlots - StationAssignmentsCountsTemp[AllGroups[i].StationPick3];

                if (AllGroups[i].StationPick1 != -1 && stationPick1AvailableSlots > 0)
                {
                    StationAssignmentsCountsTemp[AllGroups[i].StationPick1]++;
                    nFirstPicks++;
                }
                else if (AllGroups[i].StationPick1 != -1 && stationPick2AvailableSlots > 0)
                {
                    StationAssignmentsCountsTemp[AllGroups[i].StationPick2]++;
                    nSecondPicks++;
                }
                else if (AllGroups[i].StationPick1 != -1 && stationPick3AvailableSlots > 0)
                {
                    StationAssignmentsCountsTemp[AllGroups[i].StationPick3]++;
                    nThirdPicks++;
                }
                else
                    nNoPicks++;
            }

            ret += GETTING_SECOND_PICK_PENALTY * nSecondPicks;
            ret += GETTING_THIRD_PICK_PENALTY * nThirdPicks;
            ret += NOT_GETTING_ANY_PICKS_PENALTY * nNoPicks;

            return ret;
        }
        private static bool isStationAvailableAtSlot(Station station, int Day, int Slot)
        {
            int i, j;

            if (station.Capacity <= 0)
                return false;

            for (i = 0; i < station.Avail.Count; i++)
            {
                if (station.Avail[i].DayNumber == Day)
                {
                    if (station.Avail[i].Slots.IndexOf(Slot) != -1)
                        return true;
                }
            }

            return false;
        }
        private static int getStationTotalCapacityDuringWeek(Station s, int Day, int Slot)
        {
            int ret = 0;

            int i, j;

            for (i = 0; i < s.Avail.Count; i++)
            {
                if (s.Avail[i].DayNumber == Day)
                {
                    for (j = 0; j < s.Avail[i].Slots.Count; j++)
                        if (s.Avail[i].Slots[j] > Slot)
                            ret++;
                }
                else if (s.Avail[i].DayNumber > Day)
                {
                    ret += s.Avail[i].Slots.Count;
                }
            }

            ret *= s.Capacity;

            return ret;
        }
        private static int getStationIndex(Station s)
        {
            int i;

            for (i = 0; i < AllStations.Count; i++)
            {
                if (AllStations[i].Name == s.Name)
                    return i;
            }

            return -1;
        }
 public Assignment(Group g, Station s)
 {
     G = g;
     S = s;
 }