/** * Adds a general, multi-valued discrete variable, which is implemented as a set of Boolean * variables, one per value of the discrete variable, with exactly one of those variables set * <code>true</code> at any given time. * * @param c The objective function coefficients for the new Boolean variables. * @return The indexes of the newly created variables. **/ public int[] addDiscreteVariable(double[] c) { int[] result = new int[c.length]; for (int i = 0; i < c.length; ++i) result[i] = addBooleanVariable(c[i]); double[] w = new double[c.length]; Arrays.fill(w, 1); addGreaterThanConstraint(result, w, 1); try { SOSes.add(model.addSOS(idsToVariables(result), w, GRB.SOS_TYPE1)); } catch (GRBException e) { handleException(e); } return result; }
/** * Adds a general, multi-valued discrete variable, which is implemented as a set of Boolean * variables, one per value of the discrete variable, with exactly one of those variables set * <code>true</code> at any given time. * * @param c The objective function coefficients for the new Boolean variables. * @return The indexes of the newly created variables. **/ public int[] addDiscreteVariable(double[] c) { int[] result = new int[c.length]; for (int i = 0; i < c.length; ++i) result[i] = addBooleanVariable(c[i]); double[] w = new double[c.length]; Arrays.fill(w, 1); addGreaterThanConstraint(result, w, 1); try { SOSes.add(model.addSOS(idsToVariables(result), w, GRB.SOS_TYPE1)); } catch (GRBException e) { handleException(e); } return result; }