prolog

Embedding prolog engine in a dll

对着背影说爱祢 提交于 2020-01-14 13:57:29
问题 I've been working on a C++ application that embeds a prolog reasoning engine lately and, as stated in the title, I am now trying to generate a DLL instead of an executable so I can use it in another project. Since I am new to DLL development, I thought I could start with a small example. I have 3 files: likes.pl : sample prolog file defining the predicate likes/2 likes.cpp : defining the function get_food() that calls PlQuery and return the results in a std::string food.cpp : using the DLL to

Prolog isomorphic graphs

元气小坏坏 提交于 2020-01-14 13:11:51
问题 Trying to solve the isomorphic graphs problem here. Assignment info: Determine whether 2 undirected graphs are isomorphic. No isolated vertices. Number of vertices is less than 30 Edges of graphs are given as predicates, i.e. e(1, 2). f(1, 2). I'm trying to use the following approach: For every pair of edges (i.e. for every edge from graph 1 and 2) Try to bind the vertices of 2 edges If binding of vertices is impossible (i.e. another binding with one of the vertex already exists), then

Prolog isomorphic graphs

巧了我就是萌 提交于 2020-01-14 13:11:21
问题 Trying to solve the isomorphic graphs problem here. Assignment info: Determine whether 2 undirected graphs are isomorphic. No isolated vertices. Number of vertices is less than 30 Edges of graphs are given as predicates, i.e. e(1, 2). f(1, 2). I'm trying to use the following approach: For every pair of edges (i.e. for every edge from graph 1 and 2) Try to bind the vertices of 2 edges If binding of vertices is impossible (i.e. another binding with one of the vertex already exists), then

Find repeating sublists in list using Prolog

给你一囗甜甜゛ 提交于 2020-01-14 10:45:08
问题 I want to write a prolog predicate with the following output: ?- all_match([1,2,3,2,3,1,2],L). L = [[], [1], [1, 2], [2], [2, 3], [3]]. ?- all_match([1,1,1,2],L). L = [[], [1], [1, 1]]. The purpose is to find the sublists that repeat more than once. So far I found the solution to find all sublists in a list- subSet(_, []). subSet(L, [S|T]) :- append(_, L2,L), append([S|T], _, L2). But I can't figure out how to repeat the search for every element. Thanks in advance. 回答1: This code is a little

Get multiple solutions in SWI-Prolog

白昼怎懂夜的黑 提交于 2020-01-14 10:32:21
问题 I'm beginner in SWI-Prolog (but have some experience in Borland Prolog), and I've faced with a strange behavior for the following test code: test(10). test(1). It is expected for query ?-test(A) to get 2 solutions, something like A = 10; A = 1 . However, only A = 10 is produced. I don't use the cut here. Maybe backtracking is off by default in SWI-Prolog? Thanks in advance 回答1: Sorry, the answer is very simple (see SWI-Prolog doc): The user can type the semi-colon (;) or spacebar, if (s)he

zip function in Prolog

感情迁移 提交于 2020-01-14 09:32:14
问题 I'm new to Prolog and my assignment requires us to implement a function as described below: Write a Prolog predicate zip(L1,L2,L3) that is true if the list L3 is obtained by zipping (i.e. shuffling", or interleaving") the elements of the lists L1 and L2 . Update: the lists L1 and L2 can have different lengths. For instance, when you are done, you should get the following behavior: ?- zip([1,2],[a,b],[1,a,2,b]). true. ?- zip([1,2],[a,b],X). X = [1, 2, a, b] ; X = [1, 2, a, b] ; X = [1, a, 2, b

What does the “-” symbol mean in Prolog when dealing with lists?

喜夏-厌秋 提交于 2020-01-14 07:21:46
问题 I was reading the answer to this question, p(X) :- read(A), q(A,X-[]). q(end,X-X) :- !. q(A,[A|X]-Y) :- read(B), q(B,X-Y). The code above uses the syntax List-List . I somewhat understand what is going on, but I want to know what exactly what the "-" symbol/predicate does here. Also, is this SWI specific? 回答1: The (-)/2 to represent difference lists is a rather uncommon convention. In older books, another operator (\)/2 was used too. Many prefer to use two separate arguments instead. There

how to implement if-then-else in prolog

时间秒杀一切 提交于 2020-01-14 04:24:24
问题 I have tried so many things but I could not found How I can implement following wish in prolog . if list is empty call foo function else do nothing What I did: list = [] -> foo(...) ; fail. But, it does not work 回答1: fail does not mean "do nothing", but "fail (and backtrack)". You need to use true instead: ( List == [] -> foo(...) ; true ), Also, List should be a variable, so use upper case. 回答2: Another, perhaps more idiomatic, way to write this would be % foo_if_empty(?List) call foo if

Prolog - Solving game, implementing heuristics

一曲冷凌霜 提交于 2020-01-14 04:20:29
问题 I want to solve a 'game'. I have 5 circles, we can rotate circles into left or into right (90 degrees). Example: Goal: 1,2,3,....,14,15,16 Ex. of starting situations: 16,15,14,...,3,2,1 I'm using BFS. Heuristic function: heuristic(NextState,Goal,H)), Desctiption of function: For each number 1 <= i <= 16, find the minimum number of rotations needed to put i back in its correct position (disregarding all other numbers) Take the maximum over all these minimums. This amounts to reporting minimum

Prolog: Determine answers to Multiple Choice Question test where students' answers and grades are known

末鹿安然 提交于 2020-01-13 20:33:46
问题 This is a prolog problem that I have to solve. I can't seem to find a starting point. In a MCQ test where: each question has 4 choices [a,b,c,d] each question has only one correct answer (choice) there are 10 questions all questions have the same grade value (1 point, totalling 10 points) 4 students have taken this test and we have their grades: student1: [b, c, b, a, c, c, c, d, c, c] Grade: 7/10 student2: [b, d, c, a, d, d, c, c, a, b] Grade: 6/10 student3: [d, a, b, b, d, d, c, d, a, b]