$darkmode
DENOPTIM
VertexQuery.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;
20
21import java.util.List;
22
23import denoptim.graph.Vertex.BBType;
24import denoptim.graph.Vertex.VertexType;
25
30public class VertexQuery
31{
35 private Long vertexId = null;
36
40 private Integer buildingBlockId = null;
41
45 private BBType buildingBlockType = null;
46
50 private VertexType vertexType = null;
51
55 private Integer level = null;
56
60 private List<AttachmentPointQuery> apQueries = null;
61
66
71
72//------------------------------------------------------------------------------
73
77 public VertexQuery()
78 {
79 }
80
81//------------------------------------------------------------------------------
82
102 public VertexQuery(Long vID, VertexType vType, BBType bbType,
103 Integer bbID, Integer level,
104 List<AttachmentPointQuery> apQueries,
105 EdgeQuery eIn, EdgeQuery eOut)
106 {
107 this.vertexId = vID;
108 this.vertexType = vType;
109 this.buildingBlockType = bbType;
110 this.buildingBlockId = bbID;
111 this.level = level;
112 this.apQueries = apQueries;
113 this.incomingEdgeQuery = eIn;
114 this.outgoingEdgeQuery = eOut;
115 }
116
117//------------------------------------------------------------------------------
118
125 public boolean matches(Vertex v)
126 {
127 if (vertexId != null && v.getVertexId() != vertexId)
128 {
129 return false;
130 }
131
132 if (vertexType != null && v.getVertexType() != vertexType)
133 {
134 return false;
135 }
136
138 {
139 return false;
140 }
141
143 {
144 return false;
145 }
146
147 if (level != null)
148 {
149 if (v.getGraphOwner() == null)
150 {
151 return false;
152 }
153 int vertexLevel = v.getGraphOwner().getLevel(v);
154 if (vertexLevel != level)
155 {
156 return false;
157 }
158 }
159 if (apQueries != null)
160 {
161 for (AttachmentPointQuery apQuery : apQueries)
162 {
163 boolean matches = false;
165 {
166 if (apQuery.matches(ap))
167 {
168 matches = true;
169 break;
170 }
171 }
172 if (!matches)
173 {
174 return false;
175 }
176 }
177 }
178
179 if (incomingEdgeQuery != null
180 && !matchesAnyEdge(v, incomingEdgeQuery, true))
181 {
182 return false;
183 }
184
185 if (outgoingEdgeQuery != null
186 && !matchesAnyEdge(v, outgoingEdgeQuery, false))
187 {
188 return false;
189 }
190
191 return true;
192 }
193
194//------------------------------------------------------------------------------
195
196 private static boolean matchesAnyEdge(Vertex v, EdgeQuery edgeQuery,
197 boolean incoming)
198 {
199 DGraph graph = v.getGraphOwner();
200 if (graph == null)
201 {
202 return false;
203 }
204 if (incoming)
205 {
206 for (Edge e : graph.getEdgesWithTrg(v))
207 {
208 if (edgeQuery.matches(e))
209 {
210 return true;
211 }
212 }
213 } else {
214 for (Edge e : graph.getEdgesWithSrc(v))
215 {
216 if (edgeQuery.matches(e))
217 {
218 return true;
219 }
220 }
221 }
222 return false;
223 }
224
225//------------------------------------------------------------------------------
226
227}
An attachment point (AP) is a possibility to attach a Vertex onto the vertex holding the AP (i....
Query for searching AttachmentPoints.
Container for the list of vertices and the edges that connect them.
Definition: DGraph.java:104
List< Edge > getEdgesWithTrg(Vertex v)
Returns the list of edges that arrive from the given vertex, i.e., edges where the trgAP is owned by ...
Definition: DGraph.java:1061
int getLevel(Vertex v)
Calculates the level of a vertex in this graph.
Definition: DGraph.java:6026
List< Edge > getEdgesWithSrc(Vertex v)
Returns the list of edges that depart from the given vertex, i.e., edges where the srcAP is owned by ...
Definition: DGraph.java:1040
This class represents the edge between two vertices.
Definition: Edge.java:38
A query for edges: a list of properties that target edges should possess in order to match this query...
Definition: EdgeQuery.java:28
boolean matches(Edge e)
Tests whether the given edge satisfies this query.
Definition: EdgeQuery.java:97
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:304
Vertex.BBType getBuildingBlockType()
Definition: Vertex.java:318
VertexType getVertexType()
Returns the value of the vertex type.
Definition: Vertex.java:1303
DGraph getGraphOwner()
Returns the graph this vertex belongs to or null.
Definition: Vertex.java:851
abstract List< AttachmentPoint > getAttachmentPoints()
Query for searching vertices.
VertexQuery()
Constructor from empty queries.
VertexType vertexType
Query on type of vertex.
Long vertexId
Query on unique identifier or null.
Integer level
Query about the level of the vertex.
BBType buildingBlockType
Query on building block type or null.
EdgeQuery outgoingEdgeQuery
Query on the vertex' out coming connections (i.e., vertex id the source)
List< AttachmentPointQuery > apQueries
List of attachment point queries on the vertex.
Integer buildingBlockId
Query on building block in the library of building blocks, or null.
EdgeQuery incomingEdgeQuery
Query on the vertex' incoming connections (i.e., vertex id the target)
boolean matches(Vertex v)
Tests whether the given vertex satisfies all non-null criteria in this query.
static boolean matchesAnyEdge(Vertex v, EdgeQuery edgeQuery, boolean incoming)
VertexQuery(Long vID, VertexType vType, BBType bbType, Integer bbID, Integer level, List< AttachmentPointQuery > apQueries, EdgeQuery eIn, EdgeQuery eOut)
Constructor from vertex and edge queries.
The type of building block.
Definition: Vertex.java:86
Flag declaring the type of Vertex implementation.
Definition: Vertex.java:172