示例#1
0
 public Var Find(Rental re)
 {
     if (re.Condition == ECondition.MaleOnly && Gender != EGender.Male) return null;
     if (re.Condition == ECondition.FemaleOnly && Gender != EGender.Female) return null;
     if (re.Condition == ECondition.NoMale && Gender == EGender.Male) return null;
     if (re.Condition == ECondition.NoFemale && Gender == EGender.Female) return null;
     if (re.Condition == ECondition.NoBoth && Gender == EGender.Both) return null;
     Var va;
     foreach (var wi in Wishes) if ((va = wi.Find(re, this)) != null) return va;
     return null;
 }
示例#2
0
 private void Solve(Rental[] rentals, Bid[] bids)
 {
     var vars = new List<Var>();
     foreach (var bi in bids) foreach (var wi in bi.Wishes)
             wi.Regex = new Regex(wi.Area, RegexOptions.Compiled);
     foreach (var re in rentals)
     {
         foreach (var bi in bids)
         {
             var va = bi.Find(re);
             if (va == null) continue;
             vars.Add(va);
             re.Vars.Add(va);
             bi.Vars.Add(va);
         }
     }
     for (int i = 0; i < vars.Count; ++i) vars[i].ID = i;
     //foreach (var va in vars) Console.WriteLine(va);
     var mnam = "model.txt";
     using (var sw = new StreamWriter(mnam, false, Encoding.GetEncoding(932)))
     {
         sw.WriteLine("maximize");
         sw.Write("obj:");
         var rnd = new Random();
         foreach (var va in vars)
         {
             var co = va.Price + va.AddVal() + rnd.NextDouble();
             sw.Write(" + {0} v{1}", co, va.ID);
         }
         sw.WriteLine();
         sw.WriteLine("subject to");
         int cnt = 0;
         foreach (var re in rentals)
         {
             if (re.Vars.Count == 0) continue;
             sw.Write("r{0}:", cnt++);
             foreach (var va in re.Vars) sw.Write(" + v{0}", va.ID);
             sw.WriteLine(" <= 1");
         }
         foreach (var bi in bids)
         {
             if (bi.Vars.Count == 0) continue;
             sw.Write("b{0}:", cnt++);
             foreach (var va in bi.Vars) sw.Write(" + v{0}", va.ID);
             sw.WriteLine(" <= 1");
         }
         sw.WriteLine("binary");
         foreach (var va in vars) sw.WriteLine("v{0}", va.ID);
         sw.WriteLine("end");
     }
     var proc = new Process();
     proc.StartInfo.FileName = "symphony";
     proc.StartInfo.RedirectStandardOutput = true;
     proc.StartInfo.UseShellExecute = false;
     proc.StartInfo.Arguments = "-L " + mnam;
     proc.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
     proc.Start();
     var res = proc.StandardOutput.ReadToEnd();
     proc.WaitForExit();
     var pos = res.LastIndexOf("+++");
     if (pos < 0) return;
     var m = Regex.Match(res.Substring(pos + 3), "v([0-d]+)\\s+[0-9.]+");
     var sb = new StringBuilder();
     while (m.Success)
     {
         int i = int.Parse(m.Groups[1].Value);
         var va = vars[i];
         sb.AppendFormat("{0} {1} {2}\r\n", va.Rental.Name, va.Bid.Name, va.Price);
         m = m.NextMatch();
     }
     textBox1.Text = sb.ToString();
 }
示例#3
0
 public Var Find(Rental re, Bid bi)
 {
     if (MinSize > re.Size || !Regex.IsMatch(re.Address)) return null;
     if (Premium && MaxPrice >= re.PremiumPrice) return new Var(re, bi, true);
     if (MaxPrice >= re.NormalPrice) return new Var(re, bi, false);
     return null;
 }
示例#4
0
 public Var(Rental re, Bid bi, bool pr)
 {
     Rental = re;
     Bid = bi;
     Premium = pr;
 }