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;
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<>();
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> getSlotCapacity() {
95 public void setSlotCapacity(List<Long> slotCapacity) {
96 this.slotCapacity = 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());
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();
156 private void appendAttribute(StringBuilder sb, String name, String value) {
157 sb.append(name).append(" = ").append(value).append(";\n");
160 // Methods to dump minizinc parameters. THese may be very large
162 private String formatBooleanRows(List<List<Boolean>> list) {
163 StringBuilder sb = new StringBuilder();
165 for (List<Boolean> objectList : list) {
166 sb.append(row).append(formatBooleanList(objectList));
170 return sb.toString();
173 private String formatBooleanList(List<Boolean> list) {
174 StringBuilder sb = new StringBuilder();
176 for (Object object : list) {
177 sb.append(comma).append(object.toString());
180 return sb.toString();
183 private String formatLongRows(List<List<Long>> list) {
184 StringBuilder sb = new StringBuilder();
186 for (List<Long> objectList : list) {
187 sb.append(row).append(formatLongList(objectList));
191 return sb.toString();
194 private String formatLongList(List<Long> list) {
195 StringBuilder sb = new StringBuilder();
197 for (Object object : list) {
198 sb.append(comma).append(object.toString());
201 return sb.toString();