- Join over
**1.5M+ people** - Join over
**100K+ communities** - Free
**without limits** - Create
**your own community**

- Dec 05 18:06AntuVal edited #646
- Dec 05 18:06AntuVal opened #646
- Dec 04 07:40amtfjlsj commented #644
- Nov 28 03:59Travis chocoteam/choco-solver#644 broken (1567)
- Nov 28 03:58amtfjlsj commented #644
- Nov 28 03:55Travis chocoteam/choco-solver#644 broken (1566)
- Nov 28 03:55codecov-io commented #644
- Nov 28 03:55amtfjlsj synchronize #644
- Nov 28 03:51codecov-io commented #644
- Nov 28 03:51amtfjlsj synchronize #644
- Nov 28 03:41amtfjlsj commented #644
- Nov 28 03:40amtfjlsj commented #644
- Nov 28 03:39amtfjlsj commented #644
- Nov 27 17:04cprudhom opened #645
- Nov 27 16:16jgFages commented #644
- Nov 27 11:42codecov-io commented #644
- Nov 27 11:41codecov-io commented #644
- Nov 27 11:40codecov-io commented #644
- Nov 27 11:39codecov-io commented #644
- Nov 27 11:23amtfjlsj opened #644

I anwsered myself with this

```
public static void sample() {
Model model = new Model("my first problem");
Random r = new Random();
int n = 10;
int[] coef = new int[n];
for (int i = 0; i < n; i++) {
coef[i] = r.nextInt(10);
}
final BoolVar[] bs = model.boolVarArray("B", n);
model.scalar(bs, coef, "<=", 40).post();//sum bs[i]*coef[i]<=40
IntVar OBJ = model.intVar("objective", 0, 999);//defino los limites del objetivo
model.sum(bs, ">", OBJ).post(); // seteo la funcion al objetivo
model.setObjective(Model.MAXIMIZE, OBJ);
model.getSolver().solve();
int acc = 0;
for (int i = 0; i < n; i++) {
if (bs[i].getValue() == 1) {
acc += coef[i];
}
System.out.println(i + "-" + bs[i].getValue() + "-" + coef[i]);
}
System.out.println(acc);
}
```

I am currently trying to solve a real world problem (optimized orders of financial instruments) with choco and I am not very happy with my current solution.

Is this chat a good place to discuss about it or is there another place?

(I have found a link to a google group but either the group has been deleted or I do not have permission to see it)

Is this chat a good place to discuss about it or is there another place?

(I have found a link to a google group but either the group has been deleted or I do not have permission to see it)

@eobermuhlner

Based on our experience, it is precisely at this moment that you need us the most. We could tell you more easily and with more confidence whether it is possible or not. Quite often, a beginner would conclude that the approach is not working after weeks of work while we can build a solution in a couple of days. So, if this is for a commercial solution in the end, it is worth investing in a few days of consulting at the beginning. Of course, your call ;-)

Hi I'm currently trying to solve a puzzle but I'm having difficulty putting it into choco.

So I have a electrical circuit with lightbulbs of various wattage. The circuit drops in power and some lightbulbs are initially allocated at random to be shutoff so that the power drawn by all the bulbs is less than power provided by the circuit. However the lightbulbs can swap who is shutoff, as long as the total power remains less than the power provided by the circuit, and the bigger number of swapped watts between the initial random solution and our solution the better.

I think the first constraint is easy enough:

However, I'm struggling to describe how to maximize the difference of watts between the starting allocation and end allocation. From reading the docs it sounds like it should be another

So I have a electrical circuit with lightbulbs of various wattage. The circuit drops in power and some lightbulbs are initially allocated at random to be shutoff so that the power drawn by all the bulbs is less than power provided by the circuit. However the lightbulbs can swap who is shutoff, as long as the total power remains less than the power provided by the circuit, and the bigger number of swapped watts between the initial random solution and our solution the better.

I think the first constraint is easy enough:

`model.scalar(isOn, watt_per_bulb, "<=", total_watts).post();`

where `isOn`

is a simple `BoolVar[]`

describing if the bulb is on/off and watt_per_bulb is a double[].However, I'm struggling to describe how to maximize the difference of watts between the starting allocation and end allocation. From reading the docs it sounds like it should be another

`BoolVar[]`

but a View of the `isOn BoolVar[]`

, something like `model.scalar(was_swapped, watt_per_bulb, "=", total_swapped)`

and then maximize for total_swapped, but I'm not sure how to get this `was_swapped`

BoolVar[]. If anyone could point me in the right direction that would be great, thanks.
Typing this out has helped me formalise it a bit better. I created a

`was_swapped`

View BoolVar[], if the initial_state_i was 1 then was_swapped_i = negate(initial_state_i), and if initial_state_i was 0 then was_swapped_i = model.intViewScale(initial_state_i, 1). This kind of created an xor view BoolVar[]. Seems to work great.
but gets big very fast

solver.showSolutions(); shows improving solutions on the fly for optimisation problems, this is useful

and after solving (even without solution, e.g. after a time limit), solver.printStatistics(); brings interesting information too

@jgFages ty

please how can i improve my skill in constraint programming with choco solver

can you tell me if it is possible to build a Choco solver with this DEA SBM function ?

Does anyone know how to get access to the choco-solver google group (https://groups.google.com/forum/#!forum/choco-solver). Every time I try to access it I get you do not have access to this content #418 and there is no way to request access from one of the managers.

Anyone aware of a way to create soft constraints

I am new to choco-solver and have a simple problem I'm trying to solve. I'm trying to calculate the total number of employees needed for a week based on the number of employees needed at certain times of day throughout the week. I have the program working but I'm having to iterate over the number of employees needed each day to sum them up for the week. Is there an easier to just get the total number of employees for the week.

package choco;

import org.chocosolver.gui.GUI;

import org.chocosolver.solver.Model;

import org.chocosolver.solver.Solution;

import org.chocosolver.solver.Solver;

import org.chocosolver.solver.variables.IntVar;

import org.chocosolver.solver.constraints.Constraint;

import java.util.Arrays;

import java.util.Random;

public class PredictStaffingLevel2 {

public void modelAndSolve(){

```
int numOfNurses = 6, numOfDays = 8;
int numOfTimePeriods = 6, maxNumOfEEs = 15;
Model model = new Model("Determine Min Staffing Level");
IntVar[]shifts = model.intVarArray(numOfTimePeriods, 0, maxNumOfEEs);
// Shifts
// 12AM-8AM 5
// 4AM-12PM 2
// 8AM-4PM 13
// 12PM-8PM 0
// 4PM-12AM 12
// 8PM-4AM 0
int[] timePeriodStaffingLevels = new int[] {
5, // 12AM-4AM
7, // 4AM-8AM
15, // 8AM-12PM
8, // 12PM-4PM
12, // 4PM-8PM
9, // 8PM-12AM
};
for (int i = 0; i < numOfTimePeriods; i++) {
if (i == 0) {
shifts[i].ge(timePeriodStaffingLevels[i]).post();
} else {
shifts[i].add(shifts[i-1]).ge(timePeriodStaffingLevels[i]).post();
}
}
Solver solver = model.getSolver();
Solution solution = solver.findSolution();
System.out.printf("shifts\n");
for (int i = 0; i < shifts.length; i++) {
System.out.printf("shifts[%d] = %d\n", i, shifts[i].getValue());
}
if(solution != null){
for(IntVar var: model.retrieveIntVars(true)){
System.out.printf("%s\n", var);
}
System.out.printf("Solution\n");
solver.printStatistics();
} else {
for(IntVar var: model.retrieveIntVars(true)){
System.out.printf("%s\n", var);
}
}
}
public static void main(String[] args) {
new PredictStaffingLevel2().modelAndSolve();
}
```

}

Here is the output

shifts

shifts[0] = 5

shifts[1] = 2

shifts[2] = 13

shifts[3] = 0

shifts[4] = 12

shifts[5] = 0

IV_1[0] = 5

IV_1[1] = 2

IV_1[2] = 13

IV_1[3] = 0

IV_1[4] = 12

IV_1[5] = 0

cste -- 5 = 5

cste -- 0 = 0

cste -- 7 = 7

cste -- 15 = 15

cste -- 8 = 8

cste -- 12 = 12

cste -- 9 = 9

Solution

** Choco (2019-06) : Constraint Programming Solver, Copyright (c) 2010-2019

shifts

shifts[0] = 5

shifts[1] = 2

shifts[2] = 13

shifts[3] = 0

shifts[4] = 12

shifts[5] = 0

IV_1[0] = 5

IV_1[1] = 2

IV_1[2] = 13

IV_1[3] = 0

IV_1[4] = 12

IV_1[5] = 0

cste -- 5 = 5

cste -- 0 = 0

cste -- 7 = 7

cste -- 15 = 15

cste -- 8 = 8

cste -- 12 = 12

cste -- 9 = 9

Solution

** Choco (2019-06) : Constraint Programming Solver, Copyright (c) 2010-2019

- Model[Determine Min Staffing Level] features:

Variables : 13

Constraints : 6

Building time : 0.058s

User-defined search strategy : no

Complementary search strategy : no - Complete search - 1 solution found.

Model[Determine Min Staffing Level]

Solutions: 1

Building time : 0.058s

Resolution time : 0.023s

Nodes: 7 (308.2 n/s)

Backtracks: 0

Backjumps: 0

Fails: 0

Restarts: 0

I'm working on forecasting the minimum number of employees required for a shift schedule. The shift schedule is an IntVar [][] shifts and days of the week where shiftSchedule[shift][day] is bound to 0 (not assigned) to 100 where employees are numbered 1 to 100 and employees can work a maximum number of shifts per day. If the max number of shifts an employee can work in a day is 1 I'm using atMostNValues where nValues = totalNumberOfShiftsForTheDay + 1. I'm struggling to figure out how to set a constraint when an employee can work more than 1 shift in a day. Anyone have an idea how to do that? Thanks in advance.

the ones on the doc sheet seems very complicated

Can someone help me improving a solution that I modeled in choco and that is really slow?

Hello @cprudhom . I am behind the Choco releases :D . However, I observed that moving from 4.0.6 to 4.0.7 led to a regression on btrplace (still present in Choco 4.10.1). One simple problem on our homemade vector packing. The problem was solved in 4.0.6 but no longer has a solution in 4.0.7

@momo-com someone may give its opinion but you need to be more precise

@slatteryja you can have a look at

`nvalue`

constraint
Does someone know how to get a CNF from the model after I provided it with the necessary variables and constraints?

Choco is not a SAT solver but a discret constraint solver. In a SAT solver, one usally declares connjunction clauses which can be turned into a CNF. In DCS, there exists a wide variety of constraints and a clause is one of them, but it is not possible to turn a set of constraints into a CNF. Well, that is partially true: when one only declares clauses, a CNF can be get, but in that case, that would be better to use a SAT solver. In Choco, you can post a clause by using a

`LogOp`

object. In that case, the fitsy instruction is `ILogical tree = LogicTreeToolBox.toCNF(TREE, ref());`

which turns the logical expression into a CNF.
I get the same error as @slatteryja when trying to look at the Google group (which I'm not a member of):

I tried it in Firefox and Chrome, both logged in to my Google account, and in private mode browsing in both. I can see other google groups, both groups I'm a member of and open groups that I'm not a member of.

Any ideas why this might be the case, or if there is anything that could be done?

`You do not have permission to access this content. (#418)`

I tried it in Firefox and Chrome, both logged in to my Google account, and in private mode browsing in both. I can see other google groups, both groups I'm a member of and open groups that I'm not a member of.

Any ideas why this might be the case, or if there is anything that could be done?