sicstus-prolog

Passing arbitrary-sized integers from Prolog to C

独自空忆成欢 提交于 2020-01-03 07:20:29
问题 Right now, I'm learning how to interface SICStus Prolog with C code. I would like to have/use/see a C implementation of "Hamming weight" of arbitrary-sized integers in SICStus Prolog version 4. It seems to me that I need C functions for testing term types (SP_is_integer) and C functions for accessing Prolog terms (SP_get_integer, SP_get_integer_bytes). However, I'm not sure how to use SP_get_integer_bytes in a portable, robust fashion. Could you please point me to some well-crafted solid C

Prolog powerset predicate [closed]

牧云@^-^@ 提交于 2020-01-02 19:32:42
问题 It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center. Closed 6 years ago . I wish to define a predicate powerset(X, P) which is true when P is the powerset of X. Should work whether or not P is ground. 回答1: Since you use SICStus Prolog you can use the subseq0(+Sequence, ?SubSequence)

Generalizing Fibonacci sequence with SICStus Prolog

我的未来我决定 提交于 2019-12-31 01:00:15
问题 I'm trying to find a solution for a query on a generalized Fibonacci sequence (GFS). The query is: are there any GFS that have 885 as their 12th number? The initial 2 numbers may be restricted between 1 and 10. I already found the solution to find the Nth number in a sequence that starts at (1, 1) in which I explicitly define the initial numbers. Here is what I have for this: fib(1, 1). fib(2, 1). fib(N, X) :- N #> 1, Nmin1 #= N - 1, Nmin2 #= N - 2, fib(Nmin1, Xmin1), fib(Nmin2, Xmin2), X #=

Prolog, testing labeling heuristics

最后都变了- 提交于 2019-12-24 07:26:03
问题 I'm working on some experiments for comparing different labeling heuristics in Sicstus Prolog. But I keep getting into 'Resource error: insufficient memory'. I'm pretty sure I'm doing something wrong in my testcode. The following code will replicate my problem: :- use_module(library(clpfd)). :- use_module(library(lists)). atest( R, C ):- X is R * C, length( M, X), domain( M, 0, X), all_distinct( M ), statistics(walltime, [_,_SinceLast]), labeling( [],M ), statistics(walltime, [_,SinceLast]),

Expressing setup time with cumulatives

主宰稳场 提交于 2019-12-23 09:23:27
问题 There are many families of scheduling problems. I'm looking into a problem where I have families of jobs/tasks where the transition from one family to another family require reconfiguring the machine (setup time). I'm using cumulatives[2/3] to solve this problem, but I feel unsure how the setup time could be expressed. In this small example I have 10 tasks belonging to 3 different families. Any task can run on any machine, but a switch from one task in one family to another task in another

Split atom using SICStus like atomic_list_concat/3 in SWI

随声附和 提交于 2019-12-11 10:14:39
问题 i have an atom like 'id1,id2,id3' and i want to split it into list with same way as the predicate atomic_list_concat/3 in SWI . expected result ?- atomic_list_concat(L, ',', 'id1,id2,id3'). L = [id1, id2,id3] ?- atomic_list_concat([id1,id2,id3], ',', A). A = 'id1,id2,id3' anyway, is it possible to do it using DCG 回答1: without any regard to efficiency, this seems fairly similar atomic_list_concat_(L, Sep, Atom) :- ( atom(Sep), ground(L), is_list(L) ) -> list_atom(L, Sep, Atom) ; ( atom(Sep),

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

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]