0ab187b47df0b58ffad1d34efa3c4ed5ad421068
[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 maxTime;
49     private Long numLoaders;
50     private List<List<Boolean>> noConflict = new ArrayList<>();
51     private List<Long> slotCapacity = 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> getSlotCapacity() {
92         return slotCapacity;
93     }
94
95     public void setSlotCapacity(List<Long> slotCapacity) {
96         this.slotCapacity = 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         appendAttribute(sb, "noConflict", "[|\n" + formatBooleanRows(noConflict) + "|]");
148         appendAttribute(sb, "slotCapacity", "[" + formatLongList(slotCapacity) + "]");
149         appendAttribute(sb, "loaderCapacity", "[|\n" + formatLongRows(loaderCapacity) + "|]");
150         appendAttribute(sb, "attributesRange", "[" + formatLongList(attributesRange) + "]");
151         appendAttribute(sb, "attributes", "[|\n" + formatLongRows(attributes) + "|]");
152         appendAttribute(sb, "attributeConcurrencyLimit", "[|\n" + formatLongRows(attributeConcurrencyLimit) + "|]");
153         return sb.toString();
154     }
155
156     private void appendAttribute(StringBuilder sb, String name, String value) {
157         sb.append(name).append(" = ").append(value).append(";\n");
158     }
159
160     // Methods to dump minizinc parameters. THese may be very large
161     //
162     private String formatBooleanRows(List<List<Boolean>> list) {
163         StringBuilder sb = new StringBuilder();
164         String row = "";
165         for (List<Boolean> objectList : list) {
166             sb.append(row).append(formatBooleanList(objectList));
167             row = "| ";
168         }
169         sb.append("\n");
170         return sb.toString();
171     }
172
173     private String formatBooleanList(List<Boolean> list) {
174         StringBuilder sb = new StringBuilder();
175         String comma = "";
176         for (Object object : list) {
177             sb.append(comma).append(object.toString());
178             comma = ", ";
179         }
180         return sb.toString();
181     }
182
183     private String formatLongRows(List<List<Long>> list) {
184         StringBuilder sb = new StringBuilder();
185         String row = "";
186         for (List<Long> objectList : list) {
187             sb.append(row).append(formatLongList(objectList));
188             row = "| ";
189         }
190         sb.append("\n");
191         return sb.toString();
192     }
193
194     private String formatLongList(List<Long> list) {
195         StringBuilder sb = new StringBuilder();
196         String comma = "";
197         for (Object object : list) {
198             sb.append(comma).append(object.toString());
199             comma = ", ";
200         }
201         return sb.toString();
202     }
203
204 }
205
206