constraint-programming

Get multiple solutions for 0/1-Knapsack MILP with lpSolveAPI

China☆狼群 提交于 2019-12-06 02:26:07
Reproducable Example: I described a simple 0/1-Knapsack problem with lpSolveAPI in R , which should return 2 solutions: library(lpSolveAPI) lp_model= make.lp(0, 3) set.objfn(lp_model, c(100, 100, 200)) add.constraint(lp_model, c(100,100,200), "<=", 350) lp.control(lp_model, sense= "max") set.type(lp_model, 1:3, "binary") lp_model solve(lp_model) get.variables(lp_model) get.objective(lp_model) get.constr.value((lp_model)) get.total.iter(lp_model) get.solutioncount(lp_model) Problem: But get.solutioncount(lp_model) shows that there's just 1 solution found: > lp_model Model name: C1 C2 C3

Projection of solutions

偶尔善良 提交于 2019-12-06 01:59:44
Is there a possibility to tell MiniZinc to project solutions on a subset of the set of variables? Or is there any other way to enumerate all solutions that are unique wrt to evaluation of some subset of variables? I have tried to use FlatZinc annotations directly in MiniZinc, but it does not work, since the flattening process adds more defines_var annotations and my annotations are ignored. I tried the following model in MiniZinc 2.0 ( https://www.minizinc.org/2.0/index.html ) and this seems to work as you expect, i.e. that just x1 and x2 are projected (printed) in the result. int: n = 3; var

Recursion: how to avoid Python set changed set during iteration RuntimeError

荒凉一梦 提交于 2019-12-05 09:56:44
问题 Background and Problem Description: I have some code that solves the graph coloring problem (broadly defined as the problem of assigning "colors" to an undirected graph, making sure that no two vertices connected by an edge have the same color). I'm trying to implement a solution using constraint propagation to improve on the efficiency of a standard recursive backtracking algorithm, but am running into the following error: File "C:\Users\danisg\Desktop\coloring\Solver.py", line 99, in solve

Solving the Zebra puzzle (aka. Einstein puzzle) using the clpfd Prolog library

孤街醉人 提交于 2019-12-04 21:45:20
问题 I have been given an exercise to solve the zebra puzzle using a constraint solver of my choice, and I tried it using the Prolog clpfd library. I am aware that there are other more idiomatic ways to solve this problem in Prolog, but this question is specifically about the clpfd package! So the specific variation of the puzzle (given that there are many of them) I'm trying to solve is this one: There are five houses The Englishman lives in the red house The Swedish own a dog The Danish likes to

retrieve the matched model in Z3py?

时光毁灭记忆、已成空白 提交于 2019-12-04 21:05:38
In the following working example , How to retrieve the matched model? S, (cl_3,cl_39,cl_11, me_32,m_59,m_81) = EnumSort('S', ['cl_3','cl_39','cl_11','me_32','me_59','me_81']) h1, h2 = Consts('h1 h2', S) def fun(h1 , h2): conds = [ (cl_3, me_32), (cl_39, me_59), (cl_11, me_81), # ... ] and_conds = (And(h1==a, h2==b) for a,b in conds) return Or(*and_conds) For Example: as the following solver s = Solver() x1 = Const('x1', S) x2 = Const('x2', S) s.add(fun(x1,x2)) print s.check() print s.model() I'm assuming that you want the value of x1 and x2 in the model produced by Z3. If that is the case, you

How to use constraint programming for optimizing shopping baskets?

☆樱花仙子☆ 提交于 2019-12-04 07:23:32
I have a list of items I want to buy. The items are offered by different shops and different prices. The shops have individual delivery costs. I'm looking for an optimal shopping strategy (and a java library supporting it) to purchase all of the items with a minimal total price. Example: Item1 is offered at Shop1 for $100, at Shop2 for $111. Item2 is offered at Shop1 for $90, at Shop2 for $85. Delivery cost of Shop1: $10 if total order < $150; $0 otherwise Delivery cost of Shop2: $5 if total order < $50; $0 otherwise If I buy Item1 and Item2 at Shop1 the total cost is $100 + $90 +$0 = $190. If

Multi-Sudoku AI approach

末鹿安然 提交于 2019-12-04 03:28:02
问题 I'm conceptualizing a solver for a variant of sudoku called multi-sudoku , where multiple boards overlap like so: If I understand the game correctly, you must solve each grid in such a way that the overlap between any two or more grids is part of the solution for each. I'm unsure as to how I should be thinking about this. Anybody got any hints/conceptual clues? Additionally, if any topics in artificial intelligence come to mind, I'd like to hear those too. 回答1: Constraint programming (CP)

Recursion: how to avoid Python set changed set during iteration RuntimeError

浪子不回头ぞ 提交于 2019-12-03 22:35:28
Background and Problem Description: I have some code that solves the graph coloring problem (broadly defined as the problem of assigning "colors" to an undirected graph, making sure that no two vertices connected by an edge have the same color). I'm trying to implement a solution using constraint propagation to improve on the efficiency of a standard recursive backtracking algorithm, but am running into the following error: File "C:\Users\danisg\Desktop\coloring\Solver.py", line 99, in solve for color in self.domains[var]: RuntimeError: Set changed size during iteration Here, for each vertex,

Solving the Zebra puzzle (aka. Einstein puzzle) using the clpfd Prolog library

爱⌒轻易说出口 提交于 2019-12-03 15:20:52
I have been given an exercise to solve the zebra puzzle using a constraint solver of my choice, and I tried it using the Prolog clpfd library . I am aware that there are other more idiomatic ways to solve this problem in Prolog, but this question is specifically about the clpfd package! So the specific variation of the puzzle (given that there are many of them) I'm trying to solve is this one: There are five houses The Englishman lives in the red house The Swedish own a dog The Danish likes to drink tea The green house is left to the white house The owner of the green house drinks coffee The

Convert Boolean FlatZinc to CNF DIMACS

假如想象 提交于 2019-12-03 14:24:27
To solve a set of Boolean equations , I am experimenting with the Constraint-Programming Solver MiniZinc using the following input: % Solve system of Brent's equations modulo 2 % Matrix dimensions int: aRows = 3; int: aCols = 3; int: bCols = 3; int: noOfProducts = 23; % Dependent parameters int: bRows = aCols; int: cRows = aRows; int: cCols = bCols; set of int: products = 1..noOfProducts; % Corefficients are stored in arrays array[1..aRows, 1..aCols, products] of var bool: A; array[1..bRows, 1..bCols, products] of var bool: B; array[1..cRows, 1..cCols, products] of var bool: C; constraint