public static List<DesignVM> FindTopDesignsVM(List<DesignVM> DesignVMs, int number, double rate) { // number = 10 Designs to select e.g. List<DesignVM> myList = (List<DesignVM>)DesignVMs; myList.Sort(CompareDesigns); int i = 0; List<DesignVM> topDesigns = new List<DesignVM>(); List<DesignVM> badDesigns = new List<DesignVM>(); while (topDesigns.Count < number && i < myList.Count) { DesignVM candidate = (DesignVM)myList[i]; if (CheckDiversity(candidate, topDesigns,rate)) { topDesigns.Add(candidate); } else { badDesigns.Add(candidate); } i++; } // add more designs to population if there aren't enough good ones if (topDesigns.Count < number) { int howManyMore = number - topDesigns.Count; topDesigns.AddRange(badDesigns.Take(howManyMore)); // resort list in case of newly added Designs topDesigns.Sort(CompareDesigns); } return topDesigns; }
public ActionResult DeleteConfirmed(int id) { DesignVM designVM = db.DesignVMs.Find(id); db.DesignVMs.Remove(designVM); db.SaveChanges(); return(RedirectToAction("Index")); }
private static double GetDiffSize(DesignVM d, double rate) { // find size of design space double size = SizeDesignSpace(d); // top performers must differ from each other by x% of the design space in each variable double allowablesize = size * rate; double diffpercent = 0.3; return diffpercent * allowablesize; }
public static double SizeDesignSpace(DesignVM d) { double size = 0; foreach (DesignVar var in d.Design.DesignVariables) { size += Math.Pow(var.Max - var.Min, 2); } size = Math.Sqrt(size); return size; }
public List <DesignVM> GenerateAndSelectTop(int number, int popsize, double rate) { // get new generation DesignVM myFirstDesign = this.myDesignToolVM.InitialDesign; int rowIndex = this.DesignGrid.RowDefinitions.Count - 1; List <Design> seeds = new List <Design>(); if (rowIndex >= 0) { seeds = this.GetSeeds(rowIndex); } List <Design> Designs = EvolutionaryUtilities.NewGeneration(myFirstDesign.Design, seeds, EvolutionaryUtilities.NormalGenerator, popsize, rate);//, null); List <DesignVM> generatedDesigns = new List <DesignVM>(); // Run designs through grasshopper solution foreach (Design design in Designs) { for (int i = 0; i < Component.Params.Input[2].Sources.Count; i++) { GH_NumberSlider slider = Component.Params.Input[2].Sources[i] as GH_NumberSlider; if (slider != null) { slider.SetSliderValue((decimal)design.DesignVariables[i].Value); } } Grasshopper.Instances.ActiveCanvas.Document.NewSolution(true); List <Rhino.Geometry.Line> lines = Component.DesignLines; // write csv here?? List <Rhino.Geometry.Curve> curves = Component.DesignCurves; List <Rhino.Geometry.Mesh> meshes = Component.DesignMeshes; List <Rhino.Geometry.Brep> breps = Component.DesignBreps; double normscore = Component.Score / this.myDesignToolVM.getinitscore(); DesignVM genDesign = new DesignVM(lines, curves, meshes, breps, false, true, normscore, design.DesignClone()); this.myDesignToolVM.ExplorationRec.AppendLine(csvWriter.writeDesign(genDesign)); generatedDesigns.Add(genDesign); } // sort and identify top performers List <DesignVM> best = EvolutionaryUtilities.FindTopDesignsVM(generatedDesigns, number, rate); // Change main viewport design to top best design DesignVM topbest = best[0]; for (int i = 0; i < Component.Params.Input[2].Sources.Count; i++) { GH_NumberSlider slider = Component.Params.Input[2].Sources[i] as GH_NumberSlider; if (slider != null) { slider.SetSliderValue((decimal)topbest.Design.DesignVariables[i].Value); } } Grasshopper.Instances.ActiveCanvas.Document.NewSolution(true); // number = number of designs to select return(best); }
public ActionResult Edit([Bind(Include = "DVMid,DId,DesignAreaId,DesignSizeId")] DesignVM designVM) { if (ModelState.IsValid) { db.Entry(designVM).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.DesignAreaId = new SelectList(db.DesignAreas, "DesignAreaId", "AreaName", designVM.DesignAreaId); ViewBag.DId = new SelectList(db.Designs, "DesignId", "DesignName", designVM.DId); ViewBag.DesignSizeId = new SelectList(db.DesignSizes, "DsizeId", "SizeName", designVM.DesignSizeId); return(View(designVM)); }
public static string writeDesign(DesignVM design) { string delimiter = ","; string line = ""; List <DesignVar> vars = design.Design.DesignVariables; foreach (DesignVar var in vars) { line += var.Value.ToString() + delimiter; } line += design.Score.ToString(); return(line); }
private static double GetDistance(DesignVM d1, DesignVM d2) { double dist = 0; for (int i = 0; i < d1.Design.DesignVariables.Count; i++) { double var1 = d1.Design.DesignVariables[i].Value; double var2 = d2.Design.DesignVariables[i].Value; double sq = Math.Pow((var1 - var2), 2); dist += sq; } dist = Math.Sqrt(dist); return dist; }
// GET: DesignVMs/Details/5 public ActionResult Details(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } DesignVM designVM = db.DesignVMs.Find(id); if (designVM == null) { return(HttpNotFound()); } return(View(designVM)); }
public static bool IsDiverse(List<DesignVM> existing, DesignVM candidate, double rate) { double diff = GetDiffSize(candidate,rate); foreach (DesignVM s in existing) { double dist = GetDistance(s, candidate); if (dist < diff) { return false; } } return true; }
public DesignControl(DesignVM dvm, double Height, double Width, bool Clickable, IGH_Component comp)// DesignToolVM designtoolvm)//, bool Analyzed) { //dvm.Position = designtoolvm.Position; //dvm.LookDir = designtoolvm.LookDir; this.Component = (InterOptComponent)comp; this.myViewModel = dvm; //this.myViewModel.Position = designtoolvm.Position; //this.myViewModel.LookDir = designtoolvm.LookDir; this.DataContext = this.myViewModel; //this.DataContext = dvm; this.myViewModel.IsClickable = Clickable; InitializeComponent(); ControlGrid.Height = Height; ControlGrid.Width = Width; this.ScoreText.Text = String.Format("{0:0.00}", dvm.Score);//dvm.Score.ToString(); }
// GET: DesignVMs/Edit/5 public ActionResult Edit(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } DesignVM designVM = db.DesignVMs.Find(id); if (designVM == null) { return(HttpNotFound()); } ViewBag.DesignAreaId = new SelectList(db.DesignAreas, "DesignAreaId", "AreaName", designVM.DesignAreaId); ViewBag.DId = new SelectList(db.Designs, "DesignId", "DesignName", designVM.DId); ViewBag.DesignSizeId = new SelectList(db.DesignSizes, "DsizeId", "SizeName", designVM.DesignSizeId); return(View(designVM)); }
public void NewRow() { if (this.autoGenerateCheck.IsChecked == true) { myDesignToolVM.Generations.Add(MultiGenerateAndSelectTop(NCOL, (int)this.Pop.Value, this.Mut.Value)); } else { myDesignToolVM.Generations.Add(GenerateAndSelectTop(NCOL, (int)this.Pop.Value, this.Mut.Value)); } RowDefinition row = new RowDefinition() { Height = new GridLength(RowHeight) }; this.DesignGrid.RowDefinitions.Add(row); int rowIndex = this.DesignGrid.RowDefinitions.Count - 1; List <DesignVM> currentgen = myDesignToolVM.Generations[rowIndex]; //List<DesignVM> best = myDesignToolVM.Generations // add row number TextBlock GenerationNumber = new TextBlock(); GenerationNumber.Text = rowIndex.ToString(); GenerationNumber.Style = (Style)(this.Resources["RowLabel"]); GenerationNumber.Padding = new Thickness(0, 0, 0, 10); // add gen size and mutation rate TextBlock GenSize = new TextBlock(); GenSize.HorizontalAlignment = System.Windows.HorizontalAlignment.Center; GenSize.Text = "n: " + this.Pop.Value.ToString(); TextBlock MutRate = new TextBlock(); MutRate.HorizontalAlignment = System.Windows.HorizontalAlignment.Center; MutRate.Text = "r: " + this.Mut.Value.ToString("0.00"); StackPanel InfoStack = new StackPanel(); InfoStack.Width = RowHeight; InfoStack.Children.Add(GenerationNumber); InfoStack.Children.Add(GenSize); InfoStack.Children.Add(MutRate); InfoStack.VerticalAlignment = System.Windows.VerticalAlignment.Center; InfoStack.HorizontalAlignment = System.Windows.HorizontalAlignment.Center; this.DesignGrid.Children.Add(InfoStack); Grid.SetColumn(InfoStack, 0); Grid.SetRow(InfoStack, rowIndex); // create fittest members for (int i = 0; i < NCOL; i++) { // create new design control for structure Console.WriteLine(i); DesignVM dvm = currentgen[i]; DesignControl d = new DesignControl(dvm, RowHeight, RowHeight, true, this.Component);// this.DesignToolVM); //d.Margin = new Thickness(3); this.DesignGrid.Children.Add(d); Grid.SetColumn(d, i + 1); Grid.SetRow(d, rowIndex); } //add "go back" button TextBlock GoBack = new TextBlock(); GoBack.Text = "<"; GoBack.Width = RowHeight; GoBack.Style = (Style)(this.Resources["RowLabel"]); GoBack.MouseLeftButtonDown += GoBack_Click; GoBack.MouseEnter += GoBack_Hover; GoBack.MouseLeave += GoBack_Leave; this.DesignGrid.Children.Add(GoBack); Grid.SetColumn(GoBack, NCOL + 2); Grid.SetRow(GoBack, rowIndex); myScroll.UpdateLayout(); myScroll.ScrollToVerticalOffset(RowHeight); }
public static int CompareDesigns(DesignVM d1, DesignVM d2) { return d1.Score.CompareTo(d2.Score); }
private static bool CheckDiversity(DesignVM s, List<DesignVM> list, double rate) { return IsDiverse(list, s, rate); }