public SlotEvent(int max_slot, int n_event, List <DefenseEvent> all_event, AvailableSlots availslots) { this.max_slot = max_slot; this.n_event = n_event; this.availslots = availslots; this.all_event = all_event; conflict = new bool[n_event, n_event]; conflictingEvent = new bool[max_slot, n_event]; conflictsInSlot = new int[max_slot]; rand = new Random(); for (int i = 0; i < n_event; i++) { for (int j = i + 1; j < n_event; j++) { conflict[i, j] = all_event[i].IsConflict(all_event[j]); conflict[j, i] = conflict[i, j]; } } Slotevent = new int[max_slot, n_event]; slotscore = new double[max_slot]; eventsInSlot = new int[max_slot]; for (int i = 0; i < max_slot; i++) { for (int j = 0; j < n_event; j++) { Slotevent[i, j] = 0; } } foreach (var ev in all_event) { var event_no = ev.Id - 1; var slot = availslots.Info[event_no].FirstAvailableSlot(); if (slot == -1) { continue; } //System.Console.WriteLine("(" + slot.ToString() + "," + event_no.ToString() + ")"); Slotevent[slot, event_no] = 1; } calc_score(); }
public AlignmentOptimizer(DBManip db, int max_slot) { this.max_slot = max_slot; this.db = db; n_event = db.EventCount(); n_prof = db.ProfessorCount(); event_availslots = new AvailableSlots(n_event, max_slot); prof_availslots = new bool[n_prof, max_slot]; // 初期化 for (int j = 0; j < max_slot; j++) { for (int i = 0; i < n_prof; i++) { prof_availslots[i, j] = true; } } // 不都合日程読み込み for (int slot = 0; slot < max_slot; slot++) { var profs = db.GetProhibitProfs(slot + 1); // slotはoption base 1 foreach (var p in profs) // p はoption base 1 { prof_availslots[p - 1, slot] = false; } } // イベントごとに可能なスロットを計算 bool[] avail = new bool[max_slot]; var all_event = new List <DefenseEvent>(); foreach (DefenseEvent ev in db.EachEvent()) { all_event.Add(ev); for (int i = 0; i < max_slot; i++) { avail[i] = true; } foreach (var p in ev.Referee_id) // pはoption base 1 { if (p == -1) { break; } for (int i = 0; i < max_slot; i++) { avail[i] = (avail[i] && prof_availslots[p - 1, i]); } } for (int i = 0; i < max_slot; i++) { if (!avail[i]) { event_availslots.UnAvailable(ev.Id - 1, i); // ev.Idもoption base 1 } } } // 可能なスロットがないイベントがあるかどうかチェック event_availslots.CalcSummary(); // 割り当て不能イベントを書き出す if (event_availslots.Impossible) { writeImpossible(); } // 割り当て可能数が小さい方から処理する event_availslots.Sort(); // 同時に開催できないイベントを調査 // とりあえず最初に可能なスロットに全イベントを割付 Slotevent = new SlotEvent(max_slot, n_event, all_event, event_availslots); }