public Molecula CalculateGraph() { var list = new List <Edge>(); foreach (AtomView atom1 in atoms) { foreach (AtomView atom2 in atoms) { if (atom1.NodeNumber != atom2.NodeNumber) { list.Add(new Edge(atom1, atom2, null)); } } } var graph = Graph2D.fromEdges(list); var bestMolecule = molecules.FindLast((molecule) => molecule.graph.nodes.IsSubsetListOf(graph.nodes, (node) => node.NodeCode)); if (bestMolecule == null) { return(null); } var subgraph = Graph2D.mapToSubgraph(bestMolecule.graph, graph); return(new Molecula(subgraph, bestMolecule.info)); }
public static Graph2D mapToSubgraph(Graph2D thisGraph, Graph2D otherGraph) { int j = 0; var thisGraphNodes = thisGraph.nodes.OrderBy((node) => node.NodeCode).ToList(); var otherNodes = otherGraph.nodes.OrderBy((node) => node.NodeCode); var nodesMapping = new Dictionary <int, Node>(); foreach (Node otherNode in otherNodes) { if (j >= thisGraphNodes.Count) { break; } if (thisGraphNodes[j].NodeCode == otherNode.NodeCode) { nodesMapping[thisGraphNodes[j].NodeNumber] = otherNode; j++; } } var edgesMapping = new List <Edge>(); foreach (Edge thisEdge in thisGraph.edges) { var first = nodesMapping[thisEdge.first.NodeNumber]; var second = nodesMapping[thisEdge.second.NodeNumber]; edgesMapping.Add(new Edge(first, second, thisEdge.payload)); } return(Graph2D.fromEdges(edgesMapping)); }
public static Molecula MapToGraph2D(this MoleculaScriptableObject molecula) { var edges = molecula.edges.Select((edge) => new Edge(edge.first, edge.second, edge.payload)).ToList(); var graph = Graph2D.fromEdges(edges); return(new Molecula(graph, molecula.info)); }