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
9 * http://www.apache.org/licenses/LICENSE-2.0
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=================================================
19 package org.onap.optf.cmso.optimizer.clients.optimizer.models;
21 import java.util.ArrayList;
22 import java.util.List;
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
35 slotCapacity = [5, 5, 5, 5, 5];
44 attributeConcurrencyLimit = [];
46 public class OptimizerParameters {
47 private Long numElements;
48 private Long numLoaders;
49 private List<Long> elementSlotCapacity = new ArrayList<>();
51 private List<List<Boolean>> noConflict = new ArrayList<>();
52 private List<List<Long>> loaderCapacity = new ArrayList<>();
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<>();
59 public Long getNumElements() {
63 public void setNumElements(Long numElements) {
64 this.numElements = numElements;
67 public Long getMaxTime() {
71 public void setMaxTime(Long maxTime) {
72 this.maxTime = maxTime;
75 public Long getNumLoaders() {
79 public void setNumLoaders(Long numLoaders) {
80 this.numLoaders = numLoaders;
83 public List<List<Boolean>> getNoConflict() {
87 public void setNoConflict(List<List<Boolean>> noConflict) {
88 this.noConflict = noConflict;
91 public List<Long> getElementSlotCapacity() {
92 return elementSlotCapacity;
95 public void setElementSlotCapacity(List<Long> slotCapacity) {
96 this.elementSlotCapacity = slotCapacity;
99 public List<List<Long>> getLoaderCapacity() {
100 return loaderCapacity;
103 public void setLoaderCapacity(List<List<Long>> loaderCapacity) {
104 this.loaderCapacity = loaderCapacity;
107 public Long getNumAttributes() {
108 return numAttributes;
111 public void setNumAttributes(Long numAttributes) {
112 this.numAttributes = numAttributes;
115 public List<Long> getAttributesRange() {
116 return attributesRange;
119 public void setAttributesRange(List<Long> attributesRange) {
120 this.attributesRange = attributesRange;
123 public List<List<Long>> getAttributes() {
127 public void setAttributes(List<List<Long>> attributes) {
128 this.attributes = attributes;
131 public List<List<Long>> getAttributeConcurrencyLimit() {
132 return attributeConcurrencyLimit;
135 public void setAttributeConcurrencyLimit(List<List<Long>> attributeConcurrencyLimit) {
136 this.attributeConcurrencyLimit = attributeConcurrencyLimit;
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());
148 appendAttribute(sb, "noConflict", "[|\n" + formatBooleanRows(noConflict) + "|]");
149 appendAttribute(sb, "elementSlotCapacity", "[" + formatLongList(elementSlotCapacity) + "]");
150 appendAttribute(sb, "loaderCapacity", "[|\n" + formatLongRows(loaderCapacity) + "|]");
153 if (attributesRange.size() > 0) {
154 appendAttribute(sb, "attributesRange", "[" + formatLongList(attributesRange) + "]");
157 appendAttribute(sb, "attributesRange", "[]");
159 if (attributes.size() > 0) {
160 appendAttribute(sb, "attributes", "[|\n" + formatLongRows(attributes) + "|]");
163 appendAttribute(sb, "attributes", "array2d(1..numElements, 1..numAttributes, [])");
165 if (attributeConcurrencyLimit.size() > 0) {
166 appendAttribute(sb, "attributeConcurrencyLimit", "[|\n" + formatLongRows(attributeConcurrencyLimit) + "|]");
170 appendAttribute(sb, "attributeConcurrencyLimit", "array2d(1..numAttributes, 1..maxTime, [])");
172 return sb.toString();
175 private void appendAttribute(StringBuilder sb, String name, String value) {
176 sb.append(name).append(" = ").append(value).append(";\n");
179 // Methods to dump minizinc parameters. THese may be very large
181 private String formatBooleanRows(List<List<Boolean>> list) {
182 StringBuilder sb = new StringBuilder();
184 for (List<Boolean> objectList : list) {
185 sb.append(row).append(formatBooleanList(objectList));
189 return sb.toString();
192 private String formatBooleanList(List<Boolean> list) {
193 StringBuilder sb = new StringBuilder();
195 for (Object object : list) {
196 sb.append(comma).append(object.toString());
199 return sb.toString();
202 private String formatLongRows(List<List<Long>> list) {
203 StringBuilder sb = new StringBuilder();
205 for (List<Long> objectList : list) {
206 sb.append(row).append(formatLongList(objectList));
210 return sb.toString();
213 private String formatLongList(List<Long> list) {
214 StringBuilder sb = new StringBuilder();
216 for (Object object : list) {
217 sb.append(comma).append(object.toString());
220 return sb.toString();