$darkmode
DENOPTIM
APMapping.java
Go to the documentation of this file.
1/*
2 * DENOPTIM
3 * Copyright (C) 2022 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.LinkedHashMap;
22import java.util.List;
23
24import denoptim.exception.DENOPTIMException;
25
40public class APMapping extends LinkedHashMap<AttachmentPoint, AttachmentPoint>
41 implements Cloneable
42{
46 private static final long serialVersionUID = 1L;
47
48//------------------------------------------------------------------------------
49
53 public APMapping()
54 {
55 super();
56 }
57
58//------------------------------------------------------------------------------
59
71 public LinkedHashMap<Integer, Integer> toIntMappig() throws DENOPTIMException
72 {
73 LinkedHashMap<Integer, Integer> apMap = new LinkedHashMap<Integer, Integer>();
74
75 if (this.isEmpty())
76 return apMap;
77
78 Vertex ownerKey = null;
79 Vertex ownerVal = null;
80
81 for (AttachmentPoint key : this.keySet())
82 {
83 if (ownerKey != null && key.getOwner() != ownerKey)
84 {
85 throw new DENOPTIMException("Owner of AP "
86 + key.getID() + " is not vertex "
87 + ownerKey.getVertexId() + ". APMapping cannot be "
88 + "converted to int-mapping.");
89 }
90 AttachmentPoint val = this.get(key);
91 if (ownerVal != null && val.getOwner() != ownerVal)
92 {
93 throw new IllegalStateException("Owner of AP "
94 + val.getID() + " is not vertex "
95 + ownerKey.getVertexId() + ". APMapping cannot be "
96 + "converted to int-mapping.");
97 }
98 apMap.put(key.getIndexInOwner(),val.getIndexInOwner());
99
100 ownerKey = key.getOwner();
101 ownerVal = val.getOwner();
102 }
103 return apMap;
104 }
105
106//------------------------------------------------------------------------------
107
115 public boolean containsAllKeys(List<AttachmentPoint> keys)
116 {
117 return this.keySet().containsAll(keys);
118 }
119
120//------------------------------------------------------------------------------
121
129 public boolean containsAllValues(List<AttachmentPoint> keys)
130 {
131 return this.values().containsAll(keys);
132 }
133
134//------------------------------------------------------------------------------
135
139 @Override
141 {
142 APMapping c = new APMapping();
143 for (AttachmentPoint key : this.keySet())
144 {
145 c.put(key, this.get(key));
146 }
147 return c;
148 }
149
150//------------------------------------------------------------------------------
151
155 @Override
156 public String toString()
157 {
158 StringBuilder sb = new StringBuilder();
159 for (AttachmentPoint key : this.keySet())
160 {
161 sb.append(key.getID()+"-"+this.get(key).getID()+" ");
162 }
163 return sb.toString();
164 }
165
166//------------------------------------------------------------------------------
167
168}
Class representing a mapping between attachment points (APs).
Definition: APMapping.java:42
LinkedHashMap< Integer, Integer > toIntMappig()
Produces an index-based version of this mapping where each index represents the attachment point as i...
Definition: APMapping.java:71
APMapping()
Creates a mapping that links no pair of APs.
Definition: APMapping.java:53
APMapping clone()
Shallow cloning.
Definition: APMapping.java:140
static final long serialVersionUID
Version UID.
Definition: APMapping.java:46
boolean containsAllValues(List< AttachmentPoint > keys)
Check if this mapping contains all the given attachment points (APs) in the 2nd positions of the AP p...
Definition: APMapping.java:129
String toString()
Produces a human readable string based on the AP IDs.
Definition: APMapping.java:156
boolean containsAllKeys(List< AttachmentPoint > keys)
Check if this mapping contains all the given attachment points (APs) in the 1st positions of the AP p...
Definition: APMapping.java:115
An attachment point (AP) is a possibility to attach a Vertex onto the vertex holding the AP (i....
int getID()
Returns a unique integer that is used to sort list of attachment points.
A vertex is a data structure that has an identity and holds a list of AttachmentPoints.
Definition: Vertex.java:61