Skip to content

Commit

Permalink
Release 0.2.2
Browse files Browse the repository at this point in the history
  • Loading branch information
johnharding committed Jun 14, 2017
1 parent 42e5736 commit f744ffb
Show file tree
Hide file tree
Showing 6 changed files with 174 additions and 92 deletions.
Binary file modified examples/mobius.gh
Binary file not shown.
2 changes: 1 addition & 1 deletion src/Biomorpher/BiomorpherAttributes.cs
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public override GH_ObjectResponse RespondToMouseDoubleClick(GH_Canvas sender, GH
if ((ContentBox.Contains(e.CanvasLocation)))
{
myMainWindow = new BiomorpherWindow(MyOwner);
//myMainWindow.Show();
myMainWindow.Show();

return GH_ObjectResponse.Handled;
}
Expand Down
230 changes: 146 additions & 84 deletions src/Biomorpher/BiomorpherWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -217,65 +217,7 @@ public BiomorpherWindow(BiomorpherComponent Owner)

#region MAIN METHODS

/// <summary>
/// Gets the phenotype information for the current cluster representatives
/// </summary>
public void GetPhenotypes(bool clusterRepsOnly)
{

// Get geometry for each chromosome in the initial population
// TODO: Don't repeat code like this!
if (clusterRepsOnly)
{
for (int i = 0; i < population.chromosomes.Length; i++)
{

if (population.chromosomes[i].isRepresentative)
{
owner.canvas.Document.Enabled = false; // Disable the solver before tweaking sliders
owner.SetSliders(population.chromosomes[i], sliders, genePools); // Change the sliders using gene values
owner.canvas.Document.Enabled = true; // Enable the solver again
owner.ExpireSolution(true); // Now expire the main component and recompute
performanceCount = owner.GetGeometry(population.chromosomes[i]); // Get the new geometry for this particular chromosome
}
}
}

else
{
for (int i = 0; i < population.chromosomes.Length; i++)
{
owner.canvas.Document.Enabled = false; // Disable the solver before tweaking sliders
owner.SetSliders(population.chromosomes[i], sliders, genePools); // Change the sliders using gene values
owner.canvas.Document.Enabled = true; // Enable the solver again
owner.ExpireSolution(true); // Now expire the main component and recompute
performanceCount = owner.GetGeometry(population.chromosomes[i]); // Get the new geometry for this particular chromosome
}
}

// TODO: Fill up null performance values instead, because this way if you have a null performance value it kills all the others.
population.RepairPerforms();

}


/// <summary>
/// Sets the Grasshopper instance to this chromosome (does not get any data)
/// </summary>
/// <param name="chromo"></param>
public void SetInstance(Chromosome chromo)
{
owner.canvas.Document.Enabled = false;
owner.SetSliders(chromo, sliders, genePools);
owner.canvas.Document.Enabled = true;
owner.ExpireSolution(true);
HighlightedCluster = chromo.clusterId;

// Update performance tab
tab2_updatePerforms();
}



/// <summary>
/// Instantiate the population and intialise the window
/// </summary>
Expand All @@ -298,7 +240,7 @@ public void RunInit()
// 5. Now get the average performance values (cluster reps only)
population.SetAveragePerformanceValues(performanceCount, true);

// 5. Setup tab layout
// 6. Setup tab layouts
tab12_primary_permanent(1); // 1 indicates tab 1
tab1_primary_update();

Expand All @@ -309,7 +251,6 @@ public void RunInit()

tab3_secondary_settings();


// 7. Set component outputs
owner.SetComponentOut(population, BioBranches);
}
Expand All @@ -321,21 +262,24 @@ public void RunInit()
/// </summary>
public void Run(bool isPerformanceCriteriaBased)
{
// 0. AFTER selections have been made, add initial population to history when we have fitness values!
// List of biobranches. BiobranchID is a global variable
BioBranches[biobranchID].AddTwig(population);


// TODO: COPY PERFORMANCE CRITERIA TO FITNESS IF APPLICABLE (RUNNING AUTO OPTIMISATION)
// 8. Get fitness values sorted if performance optimisation is selected
// We put these before adding to history, to ensure performance display is correct.
if (isPerformanceCriteriaBased)
{
GetPhenotypes(false); // We have to do this to make sure we have performance for the whole population.
population.ResetAllFitness();
population.SetPerformanceBasedFitness(controls, performanceCount);
}

// 9. Add old population to history.
BioBranches[biobranchID].AddTwig(population);

//////////////////////////////////////////////////////////////////////////

// 1. Create new populaltion using user selection (resets fitnesses)


// 1. Create a new population using fitness values (also resets fitnesses)
Generation++;
population.RoulettePop();

Expand All @@ -348,14 +292,11 @@ public void Run(bool isPerformanceCriteriaBased)
// 3. Perform K-means clustering
population.KMeansClustering(12);

// 4. Get geometry for each chromosome
if(!isPerformanceCriteriaBased)
GetPhenotypes(true);
else
GetPhenotypes(false);
// 4. Get geometry for cluster reps only
GetPhenotypes(true);

// 5. Now get the average performance values. Cluster reps only bool here
population.SetAveragePerformanceValues(performanceCount, !isPerformanceCriteriaBased);
population.SetAveragePerformanceValues(performanceCount, true);

// 6. Update display of K-Means and representative meshes
tab1_primary_update();
Expand All @@ -370,12 +311,10 @@ public void Run(bool isPerformanceCriteriaBased)
}

/// <summary>
/// Runs when a new biobranch is spawned
/// Runs when a new biobranch is spawned.
/// </summary>
public void RunNewBranch()
{
//BioBranches[biobranchID].AddTwig(population);

// Reset generation counter
Generation = 0;

Expand All @@ -398,6 +337,65 @@ public void RunNewBranch()



/// <summary>
/// Gets the phenotype information for the current cluster representatives
/// </summary>
public void GetPhenotypes(bool clusterRepsOnly)
{

// Get geometry for each chromosome in the initial population
// TODO: Don't repeat code like this!
if (clusterRepsOnly)
{
for (int i = 0; i < population.chromosomes.Length; i++)
{

if (population.chromosomes[i].isRepresentative)
{
owner.canvas.Document.Enabled = false; // Disable the solver before tweaking sliders
owner.SetSliders(population.chromosomes[i], sliders, genePools); // Change the sliders using gene values
owner.canvas.Document.Enabled = true; // Enable the solver again
owner.ExpireSolution(true); // Now expire the main component and recompute
performanceCount = owner.GetGeometry(population.chromosomes[i]); // Get the new geometry for this particular chromosome
}
}
}

else
{
for (int i = 0; i < population.chromosomes.Length; i++)
{
owner.canvas.Document.Enabled = false; // Disable the solver before tweaking sliders
owner.SetSliders(population.chromosomes[i], sliders, genePools); // Change the sliders using gene values
owner.canvas.Document.Enabled = true; // Enable the solver again
owner.ExpireSolution(true); // Now expire the main component and recompute
performanceCount = owner.GetGeometry(population.chromosomes[i]); // Get the new geometry for this particular chromosome
}
}

// TODO: Fill up null performance values instead, because this way if you have a null performance value it kills all the others.
population.RepairPerforms();

}


/// <summary>
/// Sets the Grasshopper instance to this chromosome (does not get any data)
/// </summary>
/// <param name="chromo"></param>
public void SetInstance(Chromosome chromo)
{
owner.canvas.Document.Enabled = false;
owner.SetSliders(chromo, sliders, genePools);
owner.canvas.Document.Enabled = true;
owner.ExpireSolution(true);
HighlightedCluster = chromo.clusterId;

// Update performance tab
tab2_updatePerforms();
}



/// <summary>
/// Returns the window controls added to the dictionary
Expand Down Expand Up @@ -1181,13 +1179,15 @@ private void tab2_updatePerforms()
/// <param name="clusterID"></param>
public void AddPerformanceInfo(Population thisPop, List<Border> yourBorders, int clusterID, bool isHistory)
{

// Performance labels
double[][] performas = getRepresentativePerformas(thisPop);
string[][] criteria = getRepresentativeCriteria(thisPop);

//Add performance label
for (int i = 0; i < yourBorders.Count; i++)
{

if(!isHistory)
yourBorders[i].Margin = new Thickness(margin_w + 5, 0, margin_w, 0);
else
Expand All @@ -1199,14 +1199,15 @@ public void AddPerformanceInfo(Population thisPop, List<Border> yourBorders, int
// CAREFUL!!
try
{

double roundedPerf = Math.Round(performas[clusterID][i], 3);
if (!isHistory)
label_p = criteria[clusterID][i].ToString() + " = " + roundedPerf.ToString();
else
label_p = " " + roundedPerf.ToString();

// 6 colours MAX!
string tooltiptext = "(average = " + population.AveragePerformanceValues[i]+")";
string tooltiptext = "(average = " + thisPop.AveragePerformanceValues[i]+")";
DockPanel dp_p = createColourCodedLabel(label_p, tooltiptext, rgb_performance[i % 6], isHistory, i);

yourBorders[i].Child = dp_p;
Expand Down Expand Up @@ -1291,6 +1292,7 @@ private DockPanel createColourCodedLabel(string text, string tooltiptext, Color
}



#endregion

#region UI TAB 3 (HISTORY)
Expand Down Expand Up @@ -1362,15 +1364,19 @@ public void tab3_primary_update(bool isOptimisationRun)
// Now to populate the selected designs for this generation
for (int k = 0; k < BioBranches[biobranchID].Twigs[j].chromosomes.Length; k++)
{
bool flag = false;

Population thisPop = BioBranches[biobranchID].Twigs[j];
Chromosome thisDesign = BioBranches[biobranchID].Twigs[j].chromosomes[k];

// Potentially a little dangerous this...
if (thisDesign.isRepresentative && isOptimisationRun)
thisDesign.isChecked = true;


TagExtrema(thisPop);

if (isOptimisationRun && thisDesign.isRepresentative) flag = true;
if (!isOptimisationRun && thisDesign.isRepresentative && thisDesign.isChecked) flag = true;

// Now just show those representatives that are checked
if (thisDesign.isRepresentative && thisDesign.isChecked)
if (flag)
{
StackPanel sp = new StackPanel();
sp.VerticalAlignment = System.Windows.VerticalAlignment.Top;
Expand All @@ -1390,8 +1396,13 @@ public void tab3_primary_update(bool isOptimisationRun)

ViewportBasic vp4 = new ViewportBasic(myMesh);
vp4.Background = Brushes.White;
vp4.BorderThickness = new Thickness(0.6);
if(isOptimisationRun)

if(thisDesign.isSoupDragon || !isOptimisationRun)
vp4.BorderThickness = new Thickness(1.2);
else
vp4.BorderThickness = new Thickness(0.6);

if (thisDesign.isSoupDragon)
vp4.BorderBrush = Brushes.Red;
else
vp4.BorderBrush = Brushes.LightGray;
Expand Down Expand Up @@ -1462,6 +1473,57 @@ public void tab3_primary_update(bool isOptimisationRun)

}



/// <summary>
/// Tag extrema values during optimisation
/// </summary>
/// <param name="thisPop"></param>
public void TagExtrema(Population thisPop)
{
for (int p = 0; p < performanceCount; p++)
{
int minID = 0;
int maxID = 0;
double maxDouble = -99999999999999;
double minDouble = 99999999999999;

for (int i = 0; i < thisPop.chromosomes.Length; i++)
{
if (thisPop.chromosomes[i].isRepresentative)
{
double val = thisPop.chromosomes[i].GetPerformas()[p];

if (val > maxDouble)
{
maxDouble = val;
maxID = i;
}

if (val < minDouble)
{
minDouble = val;
minID = i;
}

}
}

// Get the associated min/max radio buttons
RadioButton radButtonMin = (RadioButton)controls["RADBUTTONMIN" + p];
RadioButton radButtonMax = (RadioButton)controls["RADBUTTONMAX" + p];

if (radButtonMin.IsChecked == true)
thisPop.chromosomes[minID].isSoupDragon = true;

if (radButtonMax.IsChecked == true)
thisPop.chromosomes[maxID].isSoupDragon = true;
}
}




/// <summary>
/// Create settings panel for Tab 3
/// </summary>
Expand Down
Loading

0 comments on commit f744ffb

Please sign in to comment.