eclipse-clp

Whats wrong with this prolog optimization solution?

随声附和 提交于 2019-12-10 18:25:56
问题 solve(Amounts) :- Total = 1505, Prices = [215, 275, 335, 355, 420, 580], length(Prices, N), length(Amounts, N), Amounts :: 0..Total//min(Prices), Amounts * Prices #= Total, labeling(Amounts). 回答1: There is nothing wrong with it. It is the example from http://eclipseclp.org/examples/xkcd287.ecl.txt, and if you hadn't omitted the line :- lib(ic). which loads the interval constraint solver, it would work just fine in ECLiPSe Prolog. 回答2: Does also work in SWI-Prolog: ?- use_module(library(clpfd)

How integer suspension will be handled when it is used in head of a condition

不想你离开。 提交于 2019-12-08 04:49:28
I have the following conditions over two variable A and B : [A,B] #:: 1..10, (A #= 3) or (B #= 3), ((A #> 3 or B #>3) -> % expression 1 ; % expression 2 ) %cntd The problem is in line 2, the solver doesn't know about the value of A and B , how to decide which branch of condition will be continued without specifying the value of the variables at line 2? The reasonable act is to decide on this branch based on the value of the variables when the solver traverse the possible values for the variables. But, As I found it goes through one of these expressions before knowing the value of the variables

How to convert vectors to arrays in ECLiPSe (CLP)? (or Prolog)

五迷三道 提交于 2019-12-05 10:51:06
I have to solve Sudoku puzzles in the format of a vector containing 9 vectors (of length 9 each). Seeing as vectors are linked lists in Prolog, I figured the search would go faster if I transformed the puzzles in a 2D array format first. Example puzzle: puzzle(P) :- P = [[_,_,8,7,_,_,_,_,6], [4,_,_,_,_,9,_,_,_], [_,_,_,5,4,6,9,_,_], [_,_,_,_,_,3,_,5,_], [_,_,3,_,_,7,6,_,_], [_,_,_,_,_,_,_,8,9], [_,7,_,4,_,2,_,_,5], [8,_,_,9,_,5,_,2,3], [2,_,9,3,_,8,7,6,_]]. I'm using ECLiPSe CLP to implement a solver. The best I've come up with so far is to write a domain like this: domain(P):- dim(P,[9,9]), P

Example channelling constraints ECLiPSe

徘徊边缘 提交于 2019-11-30 19:07:11
Can someone provide a simple example of channelling constraints? Channelling constraints are used to combine viewpoints of a constraint problem. Handbook of Constraint Programming gives a good explanation of how it works and why it can be useful: The search variables can be the variables of one of the viewpoints, say X1 (this is discussed further below). As search proceeds, propagating the constraints C1 removes values from the domains of the variables in X1. The channelling constraints may then allow values to be removed from the domains of the variables in X2. Propagating these value