$darkmode
DENOPTIM
UndirectedEdge.java
Go to the documentation of this file.
1/*
2 * DENOPTIM
3 * Copyright (C) 2019 Marco Foscato <marco.foscato@uib.no>
4 *
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU Affero General Public License as published
7 * by the Free Software Foundation, either version 3 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU Affero General Public License for more details.
14 *
15 * You should have received a copy of the GNU Affero General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 */
18
19package denoptim.graph.simplified;
20
21import denoptim.graph.AttachmentPoint;
22import denoptim.graph.Edge.BondType;
23import denoptim.graph.Vertex;
24import denoptim.utils.GeneralUtils;
25
32public class UndirectedEdge
33{
38
43
48
52 private String invariant = null;
53
54//------------------------------------------------------------------------------
55
67 this.apA = apA;
68 this.apB = apB;
69 this.bondType = bondType;
70 }
71
72//------------------------------------------------------------------------------
73
84 this(apA, apB, apA.getAPClass().getBondType());
85 }
86
87//------------------------------------------------------------------------------
88
89 private void makeInvariant()
90 {
91 Vertex tvA = apA.getOwner();
92 Vertex tvB = apB.getOwner();
93
94 String invariantTA = tvA.getBuildingBlockType().toOldInt() +
97
98 String invariantTB = tvB.getBuildingBlockType().toOldInt() +
101
102 String tmp = invariantTA + invariantTB;
103 if (invariantTA.compareTo(invariantTB) > 0)
104 tmp = invariantTB + invariantTA;
105
106 this.invariant = tmp;
107 }
108
109//------------------------------------------------------------------------------
110
111 public int compare(UndirectedEdge other)
112 {
113 if (this.invariant == null)
114 {
115 this.makeInvariant();
116 }
117 if (other.invariant == null)
118 {
119 other.makeInvariant();
120 }
121
122 int resultIgnoringBondType = this.invariant.compareTo(other.invariant);
123
124 if (resultIgnoringBondType == 0)
125 {
126 return this.bondType.compareTo(other.bondType);
127 } else {
128 return resultIgnoringBondType;
129 }
130 }
131
132//------------------------------------------------------------------------------
133
134 @Override
135 public String toString()
136 {
137 Vertex vA = apA.getOwner();
138 Vertex vB = apB.getOwner();
139
140 StringBuilder sb = new StringBuilder(64);
141 sb.append("v" + vA.getVertexId()).append("_ap")
142 .append(apA.getIndexInOwner()).append("_")
143 .append("v" + vB.getVertexId()).append("_ap")
144 .append(apB.getIndexInOwner()).append("_")
145 .append(bondType);
146
147 return sb.toString();
148 }
149
150//------------------------------------------------------------------------------
151
152}
BondType getBondType()
Definition: APClass.java:341
An attachment point (AP) is a possibility to attach a Vertex onto the vertex holding the AP (i....
APClass getAPClass()
Returns the Attachment Point class.
A vertex is a data structure that has an identity and holds a list of AttachmentPoints.
Definition: Vertex.java:61
int getBuildingBlockId()
Returns the index of the building block that should correspond to the position of the building block ...
Definition: Vertex.java:284
Vertex.BBType getBuildingBlockType()
Definition: Vertex.java:298
This class represents an undirected version of the edge between two vertices.
UndirectedEdge(AttachmentPoint apA, AttachmentPoint apB)
Constructor for an undirected edge.
String invariant
Invariant representation used to compare.
BondType bondType
The bond type associated with the connection between the fragments.
AttachmentPoint apB
Attachment point B.
UndirectedEdge(AttachmentPoint apA, AttachmentPoint apB, BondType bondType)
Constructor for an undirected edge.
AttachmentPoint apA
Attachment point A.
static String getPaddedString(int count, int number)
returns the padded string with zeroes placed to the left of 'number' up to reach the desired number o...
Possible chemical bond types an edge can represent.
Definition: Edge.java:303