clpfd

Use of cumulatives

。_饼干妹妹 提交于 2019-12-10 15:29:18
问题 I'm working on a problem where I use the cumulatives/[2,3] predicate. But I get very bad performance when I try to combine this with minimize in labeling I have the following demo. 10 task, all with duration 1, 4 machines, all with capacity=1. My goal is to minimize the total time, i.e. minimize(maximum(Es)) : :- use_module(library(clpfd)). :- use_module(library(lists)). go( Ss, Es, Ms, Tm, Lab ) :- Ss = [S1, S2, S3, S4,S5,S6,S7,S8,S9,S10], %Starttimes Es = [E1, E2, E3, E4,E5,E6,E7,E8,E9,E10]

Assigning people to beds - approaches to automate [closed]

一笑奈何 提交于 2019-12-10 14:01:33
问题 Closed . This question needs to be more focused. It is not currently accepting answers. Want to improve this question? Update the question so it focuses on one problem only by editing this post. Closed 3 years ago . I help with a youth camp every year. Assigning attendees to bedrooms is a massive task - there are 92 bedrooms and the event runs for a week, with attendees staying for varying lengths of time, and beds needing to be reused. It currently takes a volunteer ~a week to assign people

Implementing XOR function with Prolog CLPFD for 32-bit numbers

醉酒当歌 提交于 2019-12-10 13:26:11
问题 I try to implement efficient exclusive-or (XOR) in Prolog CLPFD. This should be simple predicate like: xor(A, B, AxorB). A , B , AxorB are natural numbers (with 0) and AxorB is a result of A xor B . My main problem is with efficiency. Firstly, I wasn't able to find any way to XOR two number without breaking those numbers into separate parts that could be further processed/constrained, and the process of breaking those numbers (creating proper constraints and then resolving them) is taking

SWI-Prolog CLPFD

做~自己de王妃 提交于 2019-12-10 12:51:17
问题 I'm new to prolog for constraint programming. I have an issue with CLPFD not reducing a domain as I expect it to. This is probably really simple. [A,B] ins 1..5,A*B#=5. I expect it to reduce the domain of A and B to 1\/5 But it just gives A in 1..5, A*B#=5, B in 1..5. Any suggestions would be appreciated. 回答1: While this answer is tailored to clpfd as implemented in swi-prolog, the idea/method is portable. :- use_module(library(clpfd)). Here's how we can reduce domain sizes before starting

Remove incorrect subsequent solutions without once

巧了我就是萌 提交于 2019-12-10 01:50:32
问题 I have a predicate that finds the correct solution but then goes on to find solutions which are not right. ?- data(D),data_threshold_nonredundantbumps(D,5,Bs),write(D). [3,6,7,8,2,4,5,6,9,4,7,3] D = [3, 6, 7, 8, 2, 4, 5, 6, 9|...], Bs = [bump([11], [7]), bump([8, 9], [6, 9]), bump([2, 3, 4], [6, 7, 8])] ; [3,6,7,8,2,4,5,6,9,4,7,3] D = [3, 6, 7, 8, 2, 4, 5, 6, 9|...], Bs = [bump([8, 9], [6, 9]), bump([2, 3, 4], [6, 7, 8])] ; [3,6,7,8,2,4,5,6,9,4,7,3] D = [3, 6, 7, 8, 2, 4, 5, 6, 9|...], Bs =

Mini sudoku solver in Prolog stops partway through

筅森魡賤 提交于 2019-12-09 18:40:44
问题 I'm working through 'Seven Languages in Seven Weeks', and I'm just trying to get an example from the book working. It solves a mini sudoku grid (4x4). The author is using gprolog, but I am using swi-prolog (I couldn't get gprolog to work on my VM for whatever reason, but swi-prolog worked first try). I am running Ubuntu 10.04 in VirtualBox 4.0.4 r70112 (hopefully that's not too relevant!) Here is the code in my prolog file: :- use_module(library(clpfd)). valid([]). valid([Head|Tail]) :- all

EndView game on gnu Prolog [closed]

↘锁芯ラ 提交于 2019-12-08 15:34:58
问题 As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance. Closed 7 years ago . Problem in general : we have map 8*8 and we have to fill the empty squares with number from 1 to 6.But in each column and raw number

how can I determine that all given coordinates of matrix are connected?

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-07 11:26:48
问题 Given a grid how can I determine if elements of a grid are all in a single region. In the below case is true because each element in the matrix has a neighbor. Example1: gridneighbours([[1,1],[1,2],[1,3],[2,1],[2,2],[2,3],[3,1],[4,1],[4,2]]). true. However in my second example, Example2: gridneighbours([[1,1],[1,2],[1,3],[1,4],[1,5],[1,6],[3,1],[4,1],[4,2]]). false. This is false because [3,1],[4,1],[4,2] are disjoint to the previous elements. Initially I tried using subset from Prolog to

Mandatory reification when using the 'mod' operator together with 'or'?

喜你入骨 提交于 2019-12-07 06:44:41
问题 I have written a CSP program using CLP(FD) and SWI-Prolog. I think I need to improve my constraints' writing when I use the mod operator together with #\/ in my predicates. A short example : :- use_module(library(clpfd)). constr(X,Y,Z) :- X in {1,2,3,4,5,6,7}, Y in {3,5,7}, Z in {1,2}, ((X #= 3)) #==> ((Y mod 3 #= 0) #\/ (Y mod 7 #= 0)), ((Z #= 1)) #<==> ((Y mod 3 #= 0) #\/ (Y mod 7 #= 0)). If I call constr(3,Y,Z). , I get Z #= 1 or Z #= 2 . This is because some intermediate variables

Prolog: foreach or forall for constraint solving?

夙愿已清 提交于 2019-12-07 04:07:01
问题 I'm attempting project scheduling with SWI prolog and CLP. I managed to support sequential dependencies but I'm struggling with avoiding double booking people. I have a list called Schedule containing elements like [taskname, starttime] where starttime is a free variable for the constraint solver. They're already constrained by sequential dependencies. I'm trying to write a loop like this to rule out double bookings: forall /* or maybe foreach*/ (isa(P,person), ( % Filter scheduled tasks on