public void TestMethod4() { var rs = new Rooms(10); var rnd = new Random(); var pool = new AttendeePool(); for (int i = 0; i < 5; i++) { Room r = rs.AddRoom("Room" + i.ToString()); for (int t = 0; t < 5; t++) { Event e = new Event("event" + i.ToString() + "_" + t.ToString()); r.addEvent(e); for (int j = 0; j < 3; j++) { e.attendees.Add(pool.Get("Attendee" + rnd.Next(10).ToString())); } } } Action <int, int, double> callback = (int epoch, int iter, double lossval) => { StreamWriter fs = File.AppendText(@"C:\Users\user\Desktop\result.txt"); fs.Write(epoch); fs.Write("\t"); fs.Write(iter); fs.Write("\t"); fs.WriteLine(lossval); fs.Close(); }; rs.anneal(50.0, 30, 1000, 1.2, callback); }
public void TestMethod2() { var e = new Event("イベント"); Assert.AreEqual(e.name, "イベント"); Assert.AreEqual(e.numberOfAttendees(), 0); var pool = new AttendeePool(); e.attendees.Add(pool.Get("参加者1")); e.attendees.Add(pool.Get("参加者2")); e.attendees.Add(pool.Get("参加者3")); Assert.AreEqual(e.numberOfAttendees(), 3); var e2 = new Event("イベント2"); e2.attendees.Add(pool.Get("参加者3")); e2.attendees.Add(pool.Get("参加者2")); e2.attendees.Add(pool.Get("参加者4")); Assert.AreEqual(e.overlap(e2), 2); Console.WriteLine(e.ToString()); Console.WriteLine(e2.ToString()); }
internal void DoAlignment(int max_slot, int nepoch, int niter, double tconst) { Chart chart = (Chart)form.GetControl("グラフ"); Label countlabel = (Label)form.GetControl("重複数"); Check_DB_is_not_open(); // 部屋を準備 rooms = new Rooms(max_slot); var all_room = new List <Room>(); foreach (var room_name in excel2DB.DB.EachRoom()) { all_room.Add(rooms.AddRoom(room_name)); } // 不都合日程の部屋 var p_room = rooms.AddRoom("不都合日程"); p_room.unchangable(); all_room.Add(p_room); // 部屋が使えない日時を設定 foreach (var t in excel2DB.DB.EachProhibitRoom()) { var room_id = t.Item1; var slot = t.Item2; all_room[room_id - 1].events[slot - 1] = Event.Prohibit; } // すべてのイベントを適当に部屋に割り当てる int room_no = 0; var pool = new AttendeePool(); foreach (var event_str in excel2DB.DB.EachEventString()) { var ev = new Event(event_str[1]); //学籍番号 for (int i = 5; i < 10; i++) { if (event_str[i] != "") { ev.Attendees.Add(pool.Get(event_str[i])); } } try { all_room[room_no].addEvent(ev); } catch { room_no++; if (!all_room[room_no].changable) { throw new Exception("イベントが多すぎます"); } all_room[room_no].addEvent(ev); } } // 不都合日程割り当て for (int slot = 0; slot < max_slot; slot++) { var ev = new Event("不都合" + slot.ToString()); foreach (var prof_id in excel2DB.DB.GetProhibitProfs(slot + 1)) { var name = excel2DB.DB.GetProfessorName(prof_id); ev.Attendees.Add(pool.Get(name)); } p_room.addEvent(ev); } // テスト用 //rooms.shuffle(1000); // ここから本番 void callbacklinear(int epoch, int iter, double lossval, int losscount) { int n = epoch * niter + iter; series.Points.AddXY(n, lossval); chart.Update(); countlabel.Text = losscount.ToString(); countlabel.Refresh(); form.SetIterNum(n); } double inittemp = 50.0; for (int failiter = 0; failiter < 3; failiter++) { series = new Series(); //chart.ChartAreas.First().AxisX.IsLogarithmic = true; chart.Series.Add(series); // 全ルームの全スロットで入れ替え rooms.anneal(inittemp, nepoch, niter, tconst, pool.maxid + 1, callbacklinear, false); chart.Series.Clear(); // 重複解消できたか if (countlabel.Text == "0") { break; } inittemp /= 10; } // 全ルームの同スロットで入れ替え double inittemp2 = 0.1; series = new Series(); chart.Series.Add(series); rooms.anneal(inittemp2, nepoch, niter, tconst, pool.maxid + 1, callbacklinear, true); string resultfilename = Program.GetFilename("output.csv", "Text CSV (*.csv)|*.csv|All files(*.*)|*.*"); if (resultfilename == null) { MessageBox.Show("中止しました", "Aborted", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); return; } OutputResult(resultfilename, "<?xml version = \"1.0\" encoding = \"UTF-8\" ?>" + rooms.ToString()); //OutputResult("output.csv", "<?xml version = \"1.0\" encoding = \"UTF-8\" ?>"+rooms.ToString()); string listfilename = Program.GetFilename("alllist.csv", "Text CSV (*.csv)|*.csv|All files(*.*)|*.*"); if (resultfilename == null) { MessageBox.Show("中止しました", "Aborted", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); return; } excel2DB.DB.WriteProfDefenseList(listfilename); }
internal void DoAlignment1(int max_slot, int nepoch, int niter, double tconst, int[,] slotevent) { Chart chart = (Chart)form.GetControl("グラフ"); Label countlabel = (Label)form.GetControl("重複数"); Check_DB_is_not_open(); // 部屋を準備 rooms = new Rooms(max_slot); var all_room = new List <Room>(); foreach (var room_name in excel2DB.DB.EachRoom()) { all_room.Add(rooms.AddRoom(room_name)); } // 不都合日程の部屋 var p_room = rooms.AddRoom("不都合日程"); p_room.unchangable(); all_room.Add(p_room); // すべてのイベントを部屋に割り当てる int n_event = excel2DB.DB.EventCount(); var pool = new AttendeePool(); var room_no = new int[max_slot]; for (int i = 0; i < max_slot; i++) { room_no[i] = 0; } int max_room = all_room.Count - 1; for (int event_id = 0; event_id < n_event; event_id++) { bool event_allocated = false; for (int slot = 0; slot < max_slot; slot++) { if (room_no[slot] == max_room) { continue; } if (slotevent[slot, event_id] == 1) { DefenseEvent d_ev = excel2DB.DB.GetEvent(event_id + 1); var ev = new Event(d_ev.Student_No); for (int i = 0; i < 5; i++) { if (d_ev.Referee_id[i] != -1) { ev.Attendees.Add(pool.Get(excel2DB.DB.GetProfessorName(d_ev.Referee_id[i]))); } } all_room[room_no[slot]].addEvent(ev, slot); room_no[slot]++; event_allocated = true; break; } } if (!event_allocated) { MessageBox.Show("審査" + event_id.ToString() + "が割り当てられませんでした", "Impossible", MessageBoxButtons.OK, MessageBoxIcon.Information); } } // 不都合日程割り当て for (int slot = 0; slot < max_slot; slot++) { var ev = new Event("不都合" + slot.ToString()); foreach (var prof_id in excel2DB.DB.GetProhibitProfs(slot + 1)) { var name = excel2DB.DB.GetProfessorName(prof_id); ev.Attendees.Add(pool.Get(name)); } p_room.addEvent(ev); } // ここから本番 void callbacklinear(int epoch, int iter, double lossval, int losscount) { series.Points.AddXY(epoch * niter + iter, lossval); chart.Update(); countlabel.Text = losscount.ToString(); countlabel.Refresh(); } double inittemp = 50.0; for (int failiter = 0; failiter < 3; failiter++) { series = new Series(); //chart.ChartAreas.First().AxisX.IsLogarithmic = true; chart.Series.Add(series); // 全ルームの全スロットで入れ替え rooms.anneal(inittemp, nepoch, niter, tconst, pool.maxid + 1, callbacklinear, false); chart.Series.Clear(); // 重複解消できたか if (countlabel.Text == "") { break; } inittemp /= 10; } // 全ルームの同スロットで入れ替え double inittemp2 = 0.1; series = new Series(); chart.Series.Add(series); rooms.anneal(inittemp2, nepoch, niter, tconst, pool.maxid + 1, callbacklinear, true); string resultfilename = Program.GetFilename("output.csv", "Text CSV (*.csv)|*.csv|All files(*.*)|*.*"); if (resultfilename == null) { MessageBox.Show("中止しました", "Aborted", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); return; } OutputResult(resultfilename, "<?xml version = \"1.0\" encoding = \"UTF-8\" ?>" + rooms.ToString()); }