clpfd

Prolog restrictions - puzzle

牧云@^-^@ 提交于 2019-12-11 01:47:43
问题 I'm developing a game named woodntDie. This game consists in 9 pieces which should look like this: The aim is to arrange all those pieces and make it look like a dice: This is the four final possible solutions with all those 9 pieces. I'm trying to implement some restrictions but those arent enough: sum([V5, V6, V11, V12, V17, V18, V23, V24, V29, V30, V35, V36, V41, V42, V47, V48, V53, V54], #=, 7), The sum of the opposite faces should always be 7. In this restriction I'm telling that the sum

Trying to obtain cost for a given path

廉价感情. 提交于 2019-12-11 01:32:56
问题 I am new to Prolog I am trying in Prolog a rule that gives me a given path from a node to another and also gives me the total weight of the path. I have succeeded to get all the edges of the path but I am not able to show the weight of the path. I debbuged it and it is seen that variable S adds up to the whole weight of the path but in the way back, deletes all the elements. My idea is to add the total weight to P. Code: notIn(A,[]). notIn(A,[H|T]):- A\==H,notIn(A,T). path(X,X,_,[], S, P).

arithmetic in Prolog

筅森魡賤 提交于 2019-12-10 21:05:48
问题 If I have A in 0..4, A * A #=A. Is it possible that A in 0..1. ? I would say no because 0*0 = 0, and 1*1 = 1, so these two can not be A? Thank you in advance. 回答1: What you are asking here is about the consistency of CLPFD-systems. Generally speaking, systems try to maintain consistency "as good as they can" with different kinds of tradeoff to consistency vs. speed. But most of the time they deliver only safe approximations. In this case, however, everything seems perfect (here using SICStus)

Masking in Prolog

五迷三道 提交于 2019-12-10 20:09:34
问题 I have recently been trying to figure out Prolog and been messing with lists of lists in Prolog. I am trying to create a sort of mask I suppose in p Prolog. I have a predicate that determines the difference between two lists of lists (L1 and L2 lets say) in Prolog and saves them as a list of a list(Lets say R). I have another predicate that simply states if the difference is equal to zero(noDifference). I would like to have two resulting lists of lists (M1 and M2) based off of L1 and L2

How to add domain variable to global_cardinality?

青春壹個敷衍的年華 提交于 2019-12-10 18:37:21
问题 I'm trying to add a constraint global_cardinality to my program and in the manual of SICStus Prolog is written: global_cardinality(+Xs,+Vals) global_cardinality(+Xs,+Vals,+Options) where Xs = [X1,...,Xd] is a list of integers or domain variables, and Vals = [K1-V1,...,Kn-Vn] is a list of pairs where each key Ki is a unique integer and Vi is a domain variable or an integer. True if every element of Xs is equal to some key and for each pair Ki-Vi, exactly Vi elements of Xs are equal to Ki. Now

Does the predicate `contracting/1` restore deleted inconsistent values?

半腔热情 提交于 2019-12-10 18:26:30
问题 This question is subsequent to another one I posted earlier on custom labeling in Prolog. Does the contracting/1 predicate, when used after a value assignment to a variable in a custom labeling predicate, delete the "inconsistent" values from the domain permanently ? Or are these values restored when backtracking ? 回答1: These values are of course restored on backtracking. It is the nature of pure Prolog predicates, such as CLP(FD) constraints, that everything they state is completely undone

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)

A positive_integer/1 predicate that works for big numbers

血红的双手。 提交于 2019-12-10 17:08:33
问题 In my Prolog-inspired language Brachylog, there is the possibility to label CLP(FD)-equivalent variables that have potentially infinite domains. The code that does this labelization can be found here (thanks to Markus Triska @mat). This predicate requires the existence of a predicate positive_integer/1 , which must have the following behavior: ?- positive_integer(X). X = 1 ; X = 2 ; X = 3 ; X = 4 ; … This is implemented as such in our current solution: positive_integer(N) :- length([_|_], N).

Why a clpfd variable is assigned to an actual value in a reification?

穿精又带淫゛_ 提交于 2019-12-10 16:38:58
问题 I'm working on a (SWI-)Prolog program that uses CLP(FD) constraints to find a solution for a particular problem. To do so, I happen to need what I call an "unpositioned" overlapping of two lists. That is: List La has length A List Lb has length B A > B The unpositioned overlapping list is La+Lb , where elements are added in a one-by-one fashion. However, I need Lb to have a variable offset (i.e. each lists' first element are not in the same position for the La+Lb addition. However, list Lb is

Constraint programming in SWI-Prolog

匆匆过客 提交于 2019-12-10 16:32:35
问题 I want to have a list L with three elements A,B, and C with the following constraint, :- use_module(library(clpfd)). L[A,B,C], L ins 1..3, A#=B+C. But, it gives an error - Syntax error: Operator expected. 回答1: Just answering, so that the question goes off the list of unanswered questions: The error could be also the (:-)/2, not only the missing (=)/2. So the following session wurks: Welcome to SWI-Prolog (Multi-threaded, 64 bits, Version 7.1.11) Copyright (c) 1990-2014 University of Amsterdam