clpfd and Logtalk

Help requests on developing Logtalk applications

Moderator: Paulo Moura

Post Reply
mike
Posts: 6
Joined: Tue Jun 16, 2009 2:44 pm

clpfd and Logtalk

Post by mike » Mon Jun 22, 2009 11:59 am

I pass a list of clpfd-constraints to a so called domain-object:

Code: Select all

:- object(domain).

	:- use_module(clpfd, [(#<)/2, (#=<)/2, (#>)/2, (#>=)/2, (#=)/2]).
	
	:- public(procsDomainList/1).	% A list of all domain-constraints of all processes
	
	
	/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
	   The constructor 
	   - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
	:- public(new/2).
	:- mode(new(-object_identifier, +atom), one).
	new(Domain, ProcsDomainList) :- self(Self),
	                                      create_object(Domain, [extends(Self)],	 [], [procsDomainList(ProcsDomainList)]).


	:- public(fdDom/2).
	:- mode(fdDom(-object_identifier, +atom, ?atom), one_or_more).
	fdDom(Process, Domain) :- ::procsDomainList(ProcsDomainList)....

...
I call it with e.g.:

domain::new(fu_doms, [A #>= 1, A #=< 3, B #>= A, B #=< 3, C #= A + 1, C #= B + 1]).

Now I want to evalute e.g. a process A against this domain-constraint-list as I can do it in a regular shell-session:

?- A #>= 1, A #=< 3, B #>= A, B #=< 3, C #= A + 1, C #= B + 1, fd_dom(A, ADom).

And the interesting part for me is: ADom = 1..3

I started to write to fdDom/2, but I stuck at the position where I want to pass clpfd the list and use the clpfd:fu_dom/2.

Can anyone please help me with that? Thanx.

Mike

Paulo Moura
Logtalk developer
Posts: 475
Joined: Sat May 05, 2007 8:35 am
Location: Portugal
Contact:

Re: clpfd and Logtalk

Post by Paulo Moura » Mon Jun 22, 2009 12:40 pm

When you create a new object dynamically, the clauses for the object are asserted in the object database. Therefore, any variable in the clauses, including those in your domain-constraints list, will no longer be related to the domain::new/2 call unless the domain::fdDom/2 are both part of the same goal. Consider the following example:

Code: Select all

?- A #>= 1, A #=< 3, B #>= A, B #=< 3, C #= A + 1, C #= B + 1, fd_dom(A, ADom).
ADom = 1..3,
A in 1..3,
A+1#=C,
B#>=A,
B in 1..3,
B+1#=C,
C in 2..4.

?- assertz(dl([A #>= 1, A #=< 3, B #>= A, B #=< 3, C #= A + 1, C #= B + 1])).
true.

?- dl(L), fd_dom(A, ADom).
L = [_G2840#>=1, _G2840#=<3, _G2852#>=_G2840, _G2852#=<3, _G2864#=_G2840+1, _G2864#=_G2852+1],
ADom = inf..sup.
In your code, the procsDomainList/1 predicate plays the role of the dynamic dl/1 predicate above and will result in the same problem. Note that this problem is orthogonal to Logtalk (the same would happen with Prolog modules) and results from the semantics of the CLP(FD) constraint library.

What are you trying to accomplish?
Paulo Moura
Logtalk developer

mike
Posts: 6
Joined: Tue Jun 16, 2009 2:44 pm

Re: clpfd and Logtalk

Post by mike » Mon Jun 22, 2009 1:27 pm

Well what I currently try to do is developing a declarative engine for process modelling and process navigation.

Imagine you have three processes in a process model. One of the constraints are the clpfd ones:
A must be executed minimum 1 and maximum 3 times. B minimum as often as A and maximum 3 times,
C once more than A and B (these are random examples).

Now other constraints (beside the clpfd) that I think I need to write by myself are requirements between the processes.
B needs that A has been started, C needs the completion of B, etc.

I currently have a small deductive engine for process modelling and execution which is a raw prototype. It exports a state machine
that helps you to understand how you can walk through the process model.
Now I wanted to structure some things and so came to Logtalk.


If you are interested, then I can send you a paper we have written that explains the things in more detail.
I could use some hints to the right direction.

Best regards,

Mike

Paulo Moura
Logtalk developer
Posts: 475
Joined: Sat May 05, 2007 8:35 am
Location: Portugal
Contact:

Re: clpfd and Logtalk

Post by Paulo Moura » Mon Jun 22, 2009 1:49 pm

mike wrote: Well what I currently try to do is developing a declarative engine for process modelling and process navigation.

Imagine you have three processes in a process model. One of the constraints are the clpfd ones:
A must be executed minimum 1 and maximum 3 times. B minimum as often as A and maximum 3 times,
C once more than A and B (these are random examples).
I assume that you've already played with the Logtalk/CLP(FD) examples. These examples illustrate how to use Logtalk objects to encapsulate the application logic that uses CLP(FD) constraints.
mike wrote: Now other constraints (beside the clpfd) that I think I need to write by myself are requirements between the processes. B needs that A has been started, C needs the completion of B, etc.

I currently have a small deductive engine for process modelling and execution which is a raw prototype. It exports a state machine that helps you to understand how you can walk through the process model. Now I wanted to structure some things and so came to Logtalk.
Sounds interesting.
mike wrote: If you are interested, then I can send you a paper we have written that explains the things in more detail.
Please do or provide us with a URL for downloading the paper.
Paulo Moura
Logtalk developer

mike
Posts: 6
Joined: Tue Jun 16, 2009 2:44 pm

Re: clpfd and Logtalk

Post by mike » Mon Jun 22, 2009 2:25 pm

Here is the link for the paper:
http://www.designfuerholz.de/CAISE.pdf

Well, it represents first thoughts and a raw prototype. Just to get an idea.
Now the system shall be redesigned, extended and improved.

And here is a sketch how a process can be separated in its POPM-Aspects plus
the idea to express things with constraints.
http://www.designfuerholz.de/POPM_ReDesign.png

I am thankful for any hints that bring my work to a new level.


Best regards,

Mike

Paulo Moura
Logtalk developer
Posts: 475
Joined: Sat May 05, 2007 8:35 am
Location: Portugal
Contact:

Re: clpfd and Logtalk

Post by Paulo Moura » Thu Jun 25, 2009 3:15 pm

I have already printed and read your paper. Although I'm not familiar with the area of process modeling, it seems that you may be able to take advantage of the Logtalk support for parametric objects and object proxies. The Logtalk distribution includes programming examples of both concepts. The following blog posts may also be helpful:

http://blog.logtalk.org/2009/02/24/usin ... r-objects/
http://blog.logtalk.org/2009/02/15/effi ... a-objects/

In your application, simple processes and boxes could be described by Prolog facts, which could be interpreted by Logtalk as object proxies given suitable definitions of the corresponding parametric objects. Predicates over processes and boxes could be nicely encapsulated in these parametric objects or in parametric object ancestors.

At the architecture and execution framework level, there should be easy to organize your code taking advantage of Logtalk code encapsulation and reuse features but the paper doesn't give enough details that would allow me to make informed suggestions.
Paulo Moura
Logtalk developer

mike
Posts: 6
Joined: Tue Jun 16, 2009 2:44 pm

Re: clpfd and Logtalk

Post by mike » Sat Jun 27, 2009 9:09 am

Thanx for reading the paper and giving me some hints.
By the way, my colleague has solved the upper problem with the clpfd- thing. The term_variables/2 and call/1 helps us:

Code: Select all

use_module(library(clpfd)).
Global_Domain = (PID_A #>= 2, PID_A #=< 4, PID_B #>= PID_A, PID_B #=< 3, PID_C #= PID_B + 1, PID_C #= PID_A + 1), assertz(dom_list(Global_Domain)).

dom_list(Global_Domain), term_variables(Global_Domain, [PID_A, PID_B, PID_C]), call(Global_Domain), fd_dom(PID_A, PID_A_DOM).
Currently we develop a redesign of the code in the paper, because there is just one aspect of POPM implemented. Now all should be implemented...
Logtalk will play a big part in our system (ESProNa).

Are you in principal interested in a cooperation between your chair and the University of Bayreuth, Germany? Maybe a funded research project?

Best regards,

Michael

Paulo Moura
Logtalk developer
Posts: 475
Joined: Sat May 05, 2007 8:35 am
Location: Portugal
Contact:

Re: clpfd and Logtalk

Post by Paulo Moura » Sun Jun 28, 2009 7:10 pm

mike wrote: Thanx for reading the paper and giving me some hints.
By the way, my colleague has solved the upper problem with the clpfd- thing. The term_variables/2 and call/1 helps us:
...
Did Markus already provided you with some feedback on this problem?
mike wrote: Currently we develop a redesign of the code in the paper, because there is just one aspect of POPM implemented. Now all should be implemented...
Logtalk will play a big part in our system (ESProNa).
Sounds like a nice choice ;-)
mike wrote: Are you in principal interested in a cooperation between your chair and the University of Bayreuth, Germany? Maybe a funded research project?
Yes. I'm happy to discuss with you how to best take advantage of Logtalk in the implementation of your system. Regarding a possible research project, maybe is best if we discuss it by email.
Paulo Moura
Logtalk developer

Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest