be74e37a79a433b16a629d52c572501850f9ca27
[optf/cmso.git] /
1 /*
2  *  ============LICENSE_START==============================================
3  *  Copyright (c) 2019 AT&T Intellectual Property.
4  *  =======================================================================
5  *  Licensed under the Apache License, Version 2.0 (the "License"); you may
6  *  not use this file except in compliance with the License. You may obtain a
7  *  copy of the License at
8  *
9  *         http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
14  * or implied. See the License for the specific language governing
15  * permissions and limitations under the License.
16  * ============LICENSE_END=================================================
17  */
18
19 package org.onap.optf.cmso.optimizer.clients.optimizer.models;
20
21 import java.util.ArrayList;
22 import java.util.List;
23
24
25 /*
26  * numElements = 5;
27 maxTime = 5;
28 numLoaders = 1;
29 noConflict = [| true , true , true , true , true
30  | true , true , true , true , true
31  | false , true , false , true , false
32  | false , false , false , false , false
33  | true , false , true , false , true
34  |];
35 slotCapacity = [5, 5, 5, 5, 5];
36 loaderCapacity = [|
37 5, 5, 5, 5, 5
38 |];
39
40
41 numAttributes = 0;
42 attributesRange = [];
43 attributes = [];
44 attributeConcurrencyLimit = [];
45  */
46 public class OptimizerParameters {
47     private Long numElements;
48     private Long numLoaders;
49     private List<Long> elementSlotCapacity = new ArrayList<>();
50     private Long maxTime;
51     private List<List<Boolean>> noConflict = new ArrayList<>();
52     private List<List<Long>> loaderCapacity = new ArrayList<>();
53
54     private Long numAttributes;
55     private List<Long> attributesRange = new ArrayList<>();
56     private List<List<Long>> attributes = new ArrayList<>();
57     private List<List<Long>> attributeConcurrencyLimit = new ArrayList<>();
58
59     public Long getNumElements() {
60         return numElements;
61     }
62
63     public void setNumElements(Long numElements) {
64         this.numElements = numElements;
65     }
66
67     public Long getMaxTime() {
68         return maxTime;
69     }
70
71     public void setMaxTime(Long maxTime) {
72         this.maxTime = maxTime;
73     }
74
75     public Long getNumLoaders() {
76         return numLoaders;
77     }
78
79     public void setNumLoaders(Long numLoaders) {
80         this.numLoaders = numLoaders;
81     }
82
83     public List<List<Boolean>> getNoConflict() {
84         return noConflict;
85     }
86
87     public void setNoConflict(List<List<Boolean>> noConflict) {
88         this.noConflict = noConflict;
89     }
90
91     public List<Long> getElementSlotCapacity() {
92         return elementSlotCapacity;
93     }
94
95     public void setElementSlotCapacity(List<Long> slotCapacity) {
96         this.elementSlotCapacity = slotCapacity;
97     }
98
99     public List<List<Long>> getLoaderCapacity() {
100         return loaderCapacity;
101     }
102
103     public void setLoaderCapacity(List<List<Long>> loaderCapacity) {
104         this.loaderCapacity = loaderCapacity;
105     }
106
107     public Long getNumAttributes() {
108         return numAttributes;
109     }
110
111     public void setNumAttributes(Long numAttributes) {
112         this.numAttributes = numAttributes;
113     }
114
115     public List<Long> getAttributesRange() {
116         return attributesRange;
117     }
118
119     public void setAttributesRange(List<Long> attributesRange) {
120         this.attributesRange = attributesRange;
121     }
122
123     public List<List<Long>> getAttributes() {
124         return attributes;
125     }
126
127     public void setAttributes(List<List<Long>> attributes) {
128         this.attributes = attributes;
129     }
130
131     public List<List<Long>> getAttributeConcurrencyLimit() {
132         return attributeConcurrencyLimit;
133     }
134
135     public void setAttributeConcurrencyLimit(List<List<Long>> attributeConcurrencyLimit) {
136         this.attributeConcurrencyLimit = attributeConcurrencyLimit;
137     }
138
139
140
141     public String toMiniZinc() {
142         StringBuilder sb = new StringBuilder();
143         appendAttribute(sb, "numElements", numElements.toString());
144         appendAttribute(sb, "maxTime", maxTime.toString());
145         appendAttribute(sb, "numLoaders", numLoaders.toString());
146         appendAttribute(sb, "numAttributes", numAttributes.toString());
147
148         appendAttribute(sb, "noConflict", "[|\n" + formatBooleanRows(noConflict) + "|]");
149         appendAttribute(sb, "elementSlotCapacity", "[" + formatLongList(elementSlotCapacity) + "]");
150         appendAttribute(sb, "loaderCapacity", "[|\n" + formatLongRows(loaderCapacity) + "|]");
151
152
153         if (attributesRange.size() > 0) {
154             appendAttribute(sb, "attributesRange", "[" + formatLongList(attributesRange) + "]");
155         }
156         else {
157             appendAttribute(sb, "attributesRange", "[]");
158         }
159         if (attributes.size() > 0) {
160             appendAttribute(sb, "attributes", "[|\n" + formatLongRows(attributes) + "|]");
161         }
162         else {
163             appendAttribute(sb, "attributes", "array2d(1..numElements, 1..numAttributes, [])");
164         }
165         if (attributeConcurrencyLimit.size() > 0) {
166             appendAttribute(sb, "attributeConcurrencyLimit", "[|\n" + formatLongRows(attributeConcurrencyLimit) + "|]");
167         }
168         else
169         {
170             appendAttribute(sb, "attributeConcurrencyLimit", "array2d(1..numAttributes, 1..maxTime, [])");
171         }
172         return sb.toString();
173     }
174
175     private void appendAttribute(StringBuilder sb, String name, String value) {
176         sb.append(name).append(" = ").append(value).append(";\n");
177     }
178
179     // Methods to dump minizinc parameters. THese may be very large
180     //
181     private String formatBooleanRows(List<List<Boolean>> list) {
182         StringBuilder sb = new StringBuilder();
183         String row = "";
184         for (List<Boolean> objectList : list) {
185             sb.append(row).append(formatBooleanList(objectList));
186             row = "| ";
187         }
188         sb.append("\n");
189         return sb.toString();
190     }
191
192     private String formatBooleanList(List<Boolean> list) {
193         StringBuilder sb = new StringBuilder();
194         String comma = "";
195         for (Object object : list) {
196             sb.append(comma).append(object.toString());
197             comma = ", ";
198         }
199         return sb.toString();
200     }
201
202     private String formatLongRows(List<List<Long>> list) {
203         StringBuilder sb = new StringBuilder();
204         String row = "";
205         for (List<Long> objectList : list) {
206             sb.append(row).append(formatLongList(objectList));
207             row = "| ";
208         }
209         sb.append("\n");
210         return sb.toString();
211     }
212
213     private String formatLongList(List<Long> list) {
214         StringBuilder sb = new StringBuilder();
215         String comma = "";
216         for (Object object : list) {
217             sb.append(comma).append(object.toString());
218             comma = ", ";
219         }
220         return sb.toString();
221     }
222
223 }
224
225