Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
  • Dec 05 18:06
    AntuVal edited #646
  • Dec 05 18:06
    AntuVal opened #646
  • Dec 04 07:40
    amtfjlsj commented #644
  • Nov 28 03:59
  • Nov 28 03:58
    amtfjlsj commented #644
  • Nov 28 03:55
  • Nov 28 03:55
    codecov-io commented #644
  • Nov 28 03:55
    amtfjlsj synchronize #644
  • Nov 28 03:51
    codecov-io commented #644
  • Nov 28 03:51
    amtfjlsj synchronize #644
  • Nov 28 03:41
    amtfjlsj commented #644
  • Nov 28 03:40
    amtfjlsj commented #644
  • Nov 28 03:39
    amtfjlsj commented #644
  • Nov 27 17:04
    cprudhom opened #645
  • Nov 27 16:16
    jgFages commented #644
  • Nov 27 11:42
    codecov-io commented #644
  • Nov 27 11:41
    codecov-io commented #644
  • Nov 27 11:40
    codecov-io commented #644
  • Nov 27 11:39
    codecov-io commented #644
  • Nov 27 11:23
    amtfjlsj opened #644
German Faller
@faller222
hello, can anybody help me?
Im trying to implement SSP with Choco but when I try to write something like Sum_i = Sum_j as a constraint, I dont realize how to do it.
German Faller
@faller222
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);
}
Eric Obermühlner
@eobermuhlner
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)
Jean-Guillaume Fages
@jgFages
If you wish commercial support, feel free to contact me at jg.fages@cosling.com
@eobermuhlner
Eric Obermühlner
@eobermuhlner
Commercial support might become an option once I could evaluate whether it is actually possible to build a solution. Thanks
Jean-Guillaume Fages
@jgFages
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 ;-)
Eric Obermühlner
@eobermuhlner
thanks for the input. I will investigate whether I get the budget.
Jeremy Ellis
@jeremy-ellis-tech
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: 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.
Jeremy Ellis
@jeremy-ellis-tech
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.
Charles Prud'homme
@cprudhom
@jeremy-ellis-tech that's sometimes a good strategy to explain the problem to others. I'm happy you were able to manage your issue by yourself
Bogdan Ionescu
@bogdanionescu2
hello :) it's there a way to enable logging for Choco solver? I'm eager to see that kind of debug info it can print
Jean-Guillaume Fages
@jgFages
solver.showDecisions(); displays branching decisions of the solver, it can help
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
Bogdan Ionescu
@bogdanionescu2
I'll look into it! thank you!
@jgFages ty
HushHash@道草6期
@m6_hushhash_twitter
Hello! I am a graduate year student. I am currently studying mathematical programming.
Can I use warm-start in choco ( warm-start is called hot start in cplex.)
Please tell me how to use if there are people who can understand.
CanmeNeor
@CanmeNeor
hello
please how can i improve my skill in constraint programming with choco solver
BrouceM
@BrouceM
Hi all,
I would like to use the Choco solver, mainly because it is a full Java APi without JNI stuff with dlls
I am wondering if I can build a solver for a DEA SBM slack model, like the one here:
can you tell me if it is possible to build a Choco solver with this DEA SBM function ?
image.png
BrouceM
@BrouceM
I am trying to reproduce the R plugin DEA.sbm function, wich works great but does not integrate nicely with my software for deployment on a server
Jamie Slattery
@slatteryja
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
Charles Prud'homme
@cprudhom
@slatteryja I'm not aware of such an error... but you can ask your question either here or on github
Jamie Slattery
@slatteryja
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
  • 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
Jamie Slattery
@slatteryja
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.
Bdhawa123
@Bdhawa123
anyone knows any tutorials to get started with choco
the ones on the doc sheet seems very complicated
momo-com
@momo-com
Hello
Can someone help me improving a solution that I modeled in choco and that is really slow?
Fabien Hermenier
@fhermeni
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
Charles Prud'homme
@cprudhom
@Bdhawa123 Are you talking of about https://choco-tuto.readthedocs.io/en/latest/ ?
@momo-com someone may give its opinion but you need to be more precise
@slatteryja you can have a look at nvalueconstraint
avi-natan
@avi-natan
Hi everyone,
Does someone know how to get a CNF from the model after I provided it with the necessary variables and constraints?
Charles Prud'homme
@cprudhom
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.
Mikael Zayenz Lagerkvist
@zayenz
I get the same error as @slatteryja when trying to look at the Google group (which I'm not a member of): 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?
Charles Prud'homme
@cprudhom
I just changed the visibility of the group. Can you check ?
Mikael Zayenz Lagerkvist
@zayenz
Now I could see the page to request membership, thanks!
On another note, I personally think it would be better for choco to have an open group (one that can be viewed without being a member), so that people searching for issues might find relevant discussions.
Charles Prud'homme
@cprudhom
Well, I think this is the cas now, am I wrong ?
Mikael Zayenz Lagerkvist
@zayenz
No, it requires 1) being logged in, and 2) being a member to be able to view. It is easy to check using a private browsing window.
Charles Prud'homme
@cprudhom
I’ve updated options so anyone can see threads