Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Analytical_Engine adding graph methods #2094

Merged
merged 42 commits into from
Nov 12, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
42 commits
Select commit Hold shift + click to select a range
4a922c6
Add graph methods
rolyhudson Oct 21, 2020
e3a90b3
Fix ref paths
rolyhudson Oct 21, 2020
8fbe0fa
Update ref to Diffing_Engine project
rolyhudson Oct 22, 2020
ab005c3
Set up graph filtering spatial
rolyhudson Oct 23, 2020
2dcd36d
Filtering
rolyhudson Oct 23, 2020
185aab2
Spatial graph filtering and tools.
rolyhudson Oct 23, 2020
345819e
Remove use of INode objects and variables with 'node' as name in grap…
rolyhudson Oct 26, 2020
d9d03d1
Testing alternative Diff method
rolyhudson Oct 26, 2020
f11bab6
Set up extraction of neighbourhood graph around entity.
rolyhudson Oct 26, 2020
f302ad2
Update traversal to allow collection of entities and relations
rolyhudson Oct 26, 2020
4292291
Update entity neighbourhood methods to extract subgraph of any depth.…
rolyhudson Oct 27, 2020
1fcc88b
Correct path in csproj
rolyhudson Oct 27, 2020
7df2078
Adding methods to support diagram / process view layout
rolyhudson Oct 27, 2020
18a2af0
Add framework for IProcess on relations
rolyhudson Oct 28, 2020
5ea5f75
Add copyright
rolyhudson Oct 28, 2020
fb3d6a4
Add graph method descriptions
rolyhudson Oct 28, 2020
7c6075f
Add descriptions for Graph create methods.
rolyhudson Oct 28, 2020
42482fe
Typos and consistency in descriptions
rolyhudson Oct 28, 2020
a9180f5
Merge branch 'master' of https://github.com/BHoM/BHoM_Engine into Ana…
rolyhudson Oct 28, 2020
3e92931
Set temp config for diff. Fix return object on unique entities.
rolyhudson Oct 28, 2020
ef5be80
Merge branch 'master' of https://github.com/BHoM/BHoM_Engine into Ana…
rolyhudson Oct 29, 2020
e01b844
Further descriptions and typo fixes
rolyhudson Oct 29, 2020
5f3cb0b
Update method to use customised version comparing list of IBHoMObject…
rolyhudson Oct 29, 2020
b8b03d1
Attempt fix reference in Process.
rolyhudson Oct 29, 2020
b94e4f4
Setting up ProcessGraph view methods.
rolyhudson Oct 29, 2020
9968312
Refactors for simplified dependency handling. Methods for generation …
rolyhudson Oct 30, 2020
ebb0cb1
Merge branch 'master' of https://github.com/BHoM/BHoM_Engine into Ana…
rolyhudson Nov 2, 2020
7390f1d
Updates to filtering and renaming clusters as group.
rolyhudson Nov 2, 2020
30356ac
Remove experimental layout methods
rolyhudson Nov 2, 2020
43a6f46
Remove ref to GraphFlow. Ensure spatial graph is used for Astar. Add …
rolyhudson Nov 3, 2020
61fc5f9
Merge branch 'master' of https://github.com/BHoM/BHoM_Engine into Ana…
rolyhudson Nov 4, 2020
649fb3e
Remove IProcess. Switch back to DiffConfig input on Create.Graph. Cle…
rolyhudson Nov 4, 2020
82177bf
Compliance fixes
rolyhudson Nov 4, 2020
cfd1b15
Add Create Relation method. Check for hash before removal.
rolyhudson Nov 5, 2020
826d4a3
Move IBHoMObject toRelation to convert. Ensure clone on reverse.
rolyhudson Nov 5, 2020
e4ffb75
Use IReverse not Reverse
rolyhudson Nov 5, 2020
925d747
Adjust dependency frags for usage clarity. Add relations to result of…
rolyhudson Nov 10, 2020
c8efe7d
Tidy up Graph methods to Graph folder
rolyhudson Nov 10, 2020
9f2d1cf
Add simple Creat.DiffConfig + null check when diffing. Public method …
rolyhudson Nov 11, 2020
79643e0
Merge branch 'master' of https://github.com/BHoM/BHoM_Engine into Ana…
rolyhudson Nov 11, 2020
57fcc2b
fix camel case name error.
rolyhudson Nov 11, 2020
de5b835
Merge branch 'master' of https://github.com/BHoM/BHoM_Engine into Ana…
rolyhudson Nov 12, 2020
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 55 additions & 1 deletion Analytical_Engine/Analytical_Engine.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,10 @@
<HintPath>C:\ProgramData\BHoM\Assemblies\BHoM.dll</HintPath>
<Private>False</Private>
</Reference>
<Reference Include="Diffing_oM">
<HintPath>C:\ProgramData\BHoM\Assemblies\Diffing_oM.dll</HintPath>
<Private>False</Private>
</Reference>
<Reference Include="Dimensional_oM">
<HintPath>C:\ProgramData\BHoM\Assemblies\Dimensional_oM.dll</HintPath>
<Private>False</Private>
Expand All @@ -46,6 +50,10 @@
<HintPath>C:\ProgramData\BHoM\Assemblies\Geometry_oM.dll</HintPath>
<Private>False</Private>
</Reference>
<Reference Include="Physical_oM">
<HintPath>C:\ProgramData\BHoM\Assemblies\Physical_oM.dll</HintPath>
<Private>False</Private>
</Reference>
<Reference Include="Quantities_oM">
<HintPath>C:\ProgramData\BHoM\Assemblies\Quantities_oM.dll</HintPath>
<Private>False</Private>
Expand All @@ -64,15 +72,50 @@
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="Convert\Graph\ToDataVizObjects.cs" />
<Compile Include="Convert\Graph\ToDotFormat.cs" />
<Compile Include="Convert\Graph\ToRelation.cs" />
<Compile Include="Create\Graph\DiffConfig.cs" />
<Compile Include="Create\Graph\Graph.cs" />
<Compile Include="Create\Graph\Relation.cs" />
<Compile Include="Create\IElement2D\NewInternalElement2D.cs" />
<Compile Include="Modify\Graph\RelationCurves.cs" />
<Compile Include="Modify\Graph\Layout.cs" />
<Compile Include="Modify\Graph\RemoveEntity.cs" />
<Compile Include="Modify\Graph\RemoveIsolatedEntities.cs" />
<Compile Include="Modify\Graph\Reverse.cs" />
<Compile Include="Modify\SetElements0D.cs" />
<Compile Include="Modify\SetGeometry.cs" />
<Compile Include="Modify\SetInternalElements2D.cs" />
<Compile Include="Modify\SetOutlineElements1D.cs" />
<Compile Include="Modify\Graph\UniqueEntities.cs" />
<Compile Include="Modify\Graph\UniqueEntityNames.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Query\Elements0D.cs" />
<Compile Include="Query\ExternalPolycurve.cs" />
<Compile Include="Query\Geometry.cs" />
<Compile Include="Query\Graph\Adjacency.cs" />
<Compile Include="Query\Graph\EntityNeighbourhood.cs" />
<Compile Include="Query\Graph\AStarShortestPath.cs" />
<Compile Include="Query\Graph\ClosestIElement0D.cs" />
<Compile Include="Query\Graph\Depth.cs" />
<Compile Include="Query\Graph\Destinations.cs" />
<Compile Include="Query\Graph\DiffEntities.cs" />
<Compile Include="Query\Graph\DijkstraShortestPath.cs" />
<Compile Include="Query\Graph\Entities.cs" />
<Compile Include="Query\Graph\Entity.cs" />
<Compile Include="Query\Graph\FilterEntities.cs" />
<Compile Include="Query\Graph\FilterRelations.cs" />
<Compile Include="Query\Graph\Incoming.cs" />
<Compile Include="Query\Graph\Relation.cs" />
<Compile Include="Query\Graph\RelationArrow.cs" />
<Compile Include="Query\Graph\RelationLength.cs" />
<Compile Include="Query\Graph\NotSinks.cs" />
<Compile Include="Query\Graph\Sinks.cs" />
<Compile Include="Query\Graph\Sources.cs" />
<Compile Include="Query\Graph\GraphView.cs" />
<Compile Include="Query\Graph\SubGraphs.cs" />
<Compile Include="Query\Graph\IsolatedEntities.cs" />
<Compile Include="Query\InternalElements2D.cs" />
<Compile Include="Query\IsAligned.cs" />
<Compile Include="Query\IsHorizontal.cs" />
Expand All @@ -84,13 +127,16 @@
</ItemGroup>
<ItemGroup>
<Folder Include="Compute\" />
<Folder Include="Convert\" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\BHoM_Engine\BHoM_Engine.csproj">
<Project>{1ad45c88-dd54-48e5-951f-55edfeb70e35}</Project>
<Name>BHoM_Engine</Name>
</ProjectReference>
<ProjectReference Include="..\Diffing_Engine\Diffing_Engine.csproj">
<Project>{073dfd36-0829-4792-8c32-67bf692a9413}</Project>
<Name>Diffing_Engine</Name>
</ProjectReference>
<ProjectReference Include="..\Geometry_Engine\Geometry_Engine.csproj">
<Project>{89ab2dcb-ef87-4cba-b59c-c16a8a71d333}</Project>
<Name>Geometry_Engine</Name>
Expand All @@ -99,6 +145,14 @@
<Project>{b0154405-9390-472d-9b5c-a2280823b18d}</Project>
<Name>Reflection_Engine</Name>
</ProjectReference>
<ProjectReference Include="..\Serialiser_Engine\Serialiser_Engine.csproj">
<Project>{b013f0da-7d21-4339-85fc-013edd518c6d}</Project>
<Name>Serialiser_Engine</Name>
</ProjectReference>
<ProjectReference Include="..\Spatial_Engine\Spatial_Engine.csproj">
<Project>{A84FDFE5-C267-430E-8FEC-AF4F4BF5B745}</Project>
<Name>Spatial_Engine</Name>
</ProjectReference>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<PropertyGroup>
Expand Down
69 changes: 69 additions & 0 deletions Analytical_Engine/Convert/Graph/ToDataVizObjects.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
/*
* This file is part of the Buildings and Habitats object Model (BHoM)
* Copyright (c) 2015 - 2020, the respective contributors. All rights reserved.
*
* Each contributor holds copyright over their respective contributions.
* The project versioning (Git) records all such contribution source information.
*
*
* The BHoM is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3.0 of the License, or
* (at your option) any later version.
*
* The BHoM is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this code. If not, see <https://www.gnu.org/licenses/lgpl-3.0.html>.
*/

using BH.oM.Analytical.Elements;
using BH.oM.Base;
using BH.Engine.Serialiser;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.ComponentModel;
using BH.oM.Reflection.Attributes;

namespace BH.Engine.Analytical
{
public static partial class Convert
{
/***************************************************/
/**** Public Constructors ****/
/***************************************************/

[Description("Convert a graph to CustomOBjects for visualisation.")]
[Input("graph", "The Graph to convert.")]
[Output("custom objects", "CUstom objects representing the Graph.")]
public static List<CustomObject> ToDataVizObjects(this Graph graph)
{
List<CustomObject> objects = new List<CustomObject>();
foreach (IBHoMObject entity in graph.Entities.Values.ToList())
{

string needed = "{ \"id\" :\"" + entity.Name + "\",";
needed += "\"graphElement\" : \"node\"}";
objects.Add((CustomObject)Serialiser.Convert.FromJson(needed));
}
foreach (IRelation link in graph.Relations)
{

string needed = "{ \"source\" :\"" + graph.Entities[link.Source].Name + "\",";
needed += "\"target\" :\"" + graph.Entities[link.Target].Name + "\",";
needed += "\"weight\" :\"" + link.Weight + "\",";
needed += "\"graphElement\" : \"link\" }";
objects.Add((CustomObject)Serialiser.Convert.FromJson(needed));
}
return objects;
}

/***************************************************/
}
}
68 changes: 68 additions & 0 deletions Analytical_Engine/Convert/Graph/ToDotFormat.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
/*
* This file is part of the Buildings and Habitats object Model (BHoM)
* Copyright (c) 2015 - 2020, the respective contributors. All rights reserved.
*
* Each contributor holds copyright over their respective contributions.
* The project versioning (Git) records all such contribution source information.
*
*
* The BHoM is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3.0 of the License, or
* (at your option) any later version.
*
* The BHoM is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this code. If not, see <https://www.gnu.org/licenses/lgpl-3.0.html>.
*/

using BH.oM.Analytical.Elements;
using BH.oM.Reflection.Attributes;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;

namespace BH.Engine.Analytical
{
public static partial class Convert
{
/***************************************************/
/**** Public Methods ****/
/***************************************************/

[Description("Convert a graph to DotFormat for visualisation.")]
[Input("graph", "The Graph to convert.")]
[Input("shape", "The optional DotFormat shape to represent Graph entities. Default is \"box\".")]
[Input("fontsize", "The optional DotFormat fontsize for text in the DotFormat. Default is 12.")]
[Output("dotFormat", "The DotFormat string that can be copied and pasted in on line viewers like https://visjs.github.io/vis-network/examples/network/data/dotLanguage/dotPlayground.html for quick visualisation.")]
public static string ToDotFormat(this Graph graph, string shape = "box", int fontsize = 12)
{
string pattern = "[\\~#%&*{}()/:<>?|\"-]";
string replacement = "_";

Regex regEx = new Regex(pattern);
StringBuilder sb = new StringBuilder();
sb.Append("digraph {\n");
sb.Append("node [shape = " + shape + " fontsize=" + fontsize + "]\n");
foreach (IRelation link in graph.Relations)
{
if (link.Weight == 0) continue;
string start = Regex.Replace(regEx.Replace(graph.Entities[link.Source].Name, replacement), @"\s+", "");
string end = Regex.Replace(regEx.Replace(graph.Entities[link.Target].Name, replacement), @"\s+", "");
sb.Append(string.Format("{0} -> {1}", start, end));
sb.Append(string.Format(" [ label = \"w:{0}\" ];\n", Math.Round(link.Weight, 2)));
}
sb.Append("}");
Console.WriteLine(sb.ToString());
return sb.ToString();
}
}
}
Loading