Re: [eclipse-clp-users] Constraints on structures

From: Edgaonkar, Shrirang <Shrirang.Edgaonkar_at_nttdata.com>
Date: Thu, 4 Dec 2014 01:06:38 +0000
Dear Joachim,

    Thanks for the answer. It worked.


I have one more issue. I am trying the following.

search([A[year of book], B[year of book]],0,input_order,indomain_split,complete,[]).

I want to be able to search for multiple variables within the structure using search. May be the syntax does not allow me to do so. I had to settle down for this.
search([Y, Z],0,input_order,indomain_split,complete,[]),
where Y and Z are references to the structure variables. Since I need to generate clp code, it demands a generic solution and it would be more effort with the latter approach.


Please suggest. 

Cheers,

Shrirang

:-lib(ic).
:- local struct( others(dvds, ratings) ).
:- local struct( see(others, stars) ).
:- local struct( book(author, title, year, publisher, cost, details, see) ).
top(ListOfBooks):-
  ListOfBooks = [
     D, A, B, C
 ],
  A = book{see:Z, title:"tom sawyer", author:twain},
  
  B = book{see:Z, title:"tintin and the destination moon", author:herge},
  
  B[year of book] :: -100 .. 100,
  
  A[year of book] #> 10,
  
  A[year of book] #< 20,
  
  A[cost of book] #> A[year of book],
  
  A[cost of book] #< 30,
  
  %book{year:Y} = A,
  
   %Y #> 10,
   
   %book{year:Z} = B,
  
   %Z #> 15,
  
  %search([Y, Z],0,input_order,indomain_split,complete,[]),
  
  
  search(A[cost of book],0,input_order,indomain_split,complete,[]).
  
  %search([A[year of book], B[year of book]],0,input_order,indomain_split,complete,[]).



________________________________________
From: Joachim Schimpf [jschimpf_at_coninfer.com]
Sent: 04 December 2014 02:12:53
To: eclipse-clp-users_at_lists.sourceforge.net
Subject: Re: [eclipse-clp-users] Constraints on structures

On 03/12/14 09:10, Edgaonkar, Shrirang wrote:
> Dear clp users,
>
>    I have the following structure. I would like to have constraint on year like
> A:year > 10 and then have eclipse resolve the constraint.
>
> :-lib(ic).
>
> :- local struct( others(dvds, ratings) ).
> :- local struct( see(others, stars) ).
> :- local struct( book(author, title, year, publisher, cost, details, see) ).
>
> top(ListOfBooks):-
>    ListOfBooks = [
>       D, A, B, C
>   ],
>    A = book{see:Z, title:"tom sawyer", author:twain, cost:23.34}.
>

Some ways to do that (assuming A is a book{} structure):

     book{year:Y} = A,         % extract the year field from the book structure A
     Y #> 10.

or

     arg(year of book, A, Y),  % extract the year field from the book structure A
     Y #> 10.

or

     A[year of book] #> 10.


-- Joachim





------------------------------------------------------------------------------
Download BIRT iHub F-Type - The Free Enterprise-Grade BIRT Server
from Actuate! Instantly Supercharge Your Business Reports and Dashboards
with Interactivity, Sharing, Native Excel Exports, App Integration & more
Get technology previously reserved for billion-dollar corporations, FREE
http://pubads.g.doubleclick.net/gampad/clk?id=164703151&iu=/4140/ostg.clktrk
_______________________________________________
ECLiPSe-CLP-Users mailing list
ECLiPSe-CLP-Users_at_lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/eclipse-clp-users

______________________________________________________________________
Disclaimer: This email and any attachments are sent in strictest confidence
for the sole use of the addressee and may contain legally privileged,
confidential, and proprietary data. If you are not the intended recipient,
please advise the sender by replying promptly to this email and then delete
and destroy this email and any attachments without any further use, copying
or forwarding.
Received on Thu Dec 04 2014 - 01:07:21 CET

This archive was generated by hypermail 2.2.0 : Thu Dec 04 2014 - 09:13:15 CET