eclipse-clp

Is there a way to use module/2 in ECLiPSe Prolog?

浪尽此生 提交于 2020-01-25 03:39:06
问题 In SWI-Prolog, I am using code such as at the beginning of a module text file: :- module(foo, [bar/2]). :- use_module(library(jack)). I don't want to change my code . How can I neverthelss use ECLiPSe Prolog (*). Is there some library that defines a module/2 directive in ECLiPSe Prolog? Best Regards (*) http://eclipseclp.org/ 回答1: The following code defines a macro that maps module/2 into module/3 directives: :- export macro((:-)/1, translate_directive/2, [top_only]). translate_directive( (:-

Example channelling constraints ECLiPSe

情到浓时终转凉″ 提交于 2020-01-11 01:41:17
问题 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

Measuring execution time ECLiPSe CLP (or Prolog)

醉酒当歌 提交于 2019-12-23 21:28:30
问题 How do I measure the execution time of a method in ECLiPSe CLP? Currently, I have this: measure_traditional(Difficulty,Selection,Choice):- statistics(runtime, _), time(solve_traditional(Difficulty,Selection,Choice,_)), time(solve_traditional(Difficulty,Selection,Choice,_)), time(solve_traditional(Difficulty,Selection,Choice,_)), time(solve_traditional(Difficulty,Selection,Choice,_)), time(solve_traditional(Difficulty,Selection,Choice,_)), time(solve_traditional(Difficulty,Selection,Choice,_))

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

若如初见. 提交于 2019-12-23 01:27:09
问题 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

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

假如想象 提交于 2019-12-22 06:29:00
问题 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

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

北城以北 提交于 2019-12-22 06:28:23
问题 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

Eclipse CLP labeling: exclude permutations

会有一股神秘感。 提交于 2019-12-12 19:21:58
问题 I am solving a scheduling problem (briefly described here: SWI Prolog CLP(FD) scheduling switched to ECLP). I am able to get some solution quickly, but now I want to incorporate some optimization task. A part of the problem/schedule row looks like D1,D2,N1,N2,A0,A1,A2,..,A9 where some cost for this variables is C1,C1,C1,C1,C2,C2,C2,...,C2 . So from this point of view any permutation of assignments to A0..A9 has the same cost. But, obviously, during the labeling process the solver backtracks

How to implement This MP problem in ECLIPSE CLP or Prolog?

扶醉桌前 提交于 2019-12-11 15:55:47
问题 I want to implement this Summations as Objective and Constraints(1-6) Could anyone help me that how I can Implement them? OBJ: Min ∑(i=1..N)∑(j=1..N) Cij * ∑(k=1..K)Xijk constraint : ∑(k=1..K) Yik=1 (for all i in N) 回答1: The following answer is specific to ECLiPSe (it uses loops, array and array slice notation, which are not part of standard Prolog). I assume that N and K (and presumably C ) are given, and your matrices are declared as dim(C, [N,N]), dim(X, [N,N,K]), dim(Y, [N,K]), You can

How can I speed up this program? It is a coin holder calculation

不羁的心 提交于 2019-12-11 04:10:02
问题 So this is a program where it calculates the fewest number of coins to carry with certain values on these coins. The program works, but it's way too slow... When you replace the length of the values 7 or less, it works... But 8 or above, it's really, really slow. Is there any way to speed up this program? % LIBRARIES NEEDED FOR FUNCTION TO WORK :- lib(ic). :- lib(ic_global). :- lib(branch_and_bound). questionSix(Values, Coins) :- init_vars(Values, Coins), coin_cons(Values, Coins, Pockets),