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

- Oct 17 08:14Travis chocoteam/choco-solver (modules) errored (1501)
- Oct 17 08:13
cprudhom on modules

Update solver exports (compare)

- Oct 17 05:15Travis chocoteam/choco-solver (modules) errored (1500)
- Oct 17 05:14
cprudhom on modules

Fix maven compilation failure b… (compare)

- Oct 16 13:43
cprudhom on modules

Fix maven compilation failure (compare)

- Oct 16 13:10
cprudhom on modules

Partially fix maven compilation… Partially fix maven compilation… Fix maven compilation failure (compare)

- Oct 15 09:13
cprudhom on master

Update README.md (compare)

- Oct 14 16:03xcorail closed #608
- Oct 14 13:33
cprudhom on master

Add LGTM badge + deal with LGTM… (compare)

- Oct 14 13:22cprudhom commented #634
- Oct 14 13:15
cprudhom on master

Prepare the code for the next v… (compare)

- Oct 14 13:07
cprudhom on 4.10.2

- Oct 14 13:07
cprudhom on master

initiate release 4.10.2 (compare)

- Oct 14 13:03
cprudhom on master

Update CHANGES.md initiate release 4.10.1 (compare)

- Oct 10 14:47codecov-io commented #636
- Oct 10 14:47codecov-io commented #636
- Oct 10 14:47codecov-io commented #636
- Oct 10 14:46codecov-io commented #636
- Oct 10 14:45ingambe closed #636
- Oct 10 14:45ingambe commented #636

Sorry, I face a bug when calculate the minimize "d2".the system returns "distance d2 : 178"

but the why the minimize "distance d2" not be :"2468(y7min) - 3024(y6max) = -556"?

but the why the minimize "distance d2" not be :"2468(y7min) - 3024(y6max) = -556"?

@cprudhom

I will be grateful if you could help me to tackle this problem. Thanks.

But, you should use a while-loop for solving the problem, since many intermediate solutions can be found before finding the optimal one

```
while(model.getSolver(){ //4.Print solution
System.out.println("distance y6 : " + y6.getValue());
System.out.println("distance y7 : " + y7.getValue());
System.out.println("distance d2 : " + d2.getValue());
}
```

I want to know the time complexity of Forward checking algorithm with Minimum Remaining Value.Somebody explain me

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