Re: instantiation problem

From: Andrew Eremin <a.eremin_at_icparc.ic.ac.uk>
Date: Tue 09 Mar 2004 02:39:19 PM GMT
Message-ID: <404DD717.2040903@icparc.ic.ac.uk>
Martin Lorenz wrote:
> Dear colleagues,
> 
> allthough my prolog skills are not the worst i am somehow stuck in a
> dead-end street...
> 
> I try to formulate the following problem:
> 
> i have a set of facts with numerical values like
> p(10,10).
> p(20,10).
> p(40,60).
> etc...
> 
> Now I need to pose some query which is able to instantiate p/2 with
> values that are up to X (at most 4 in my case) off the values given by
> the facts AND I will need to infer the deviation value that led to the
> given instantiation thus having some p/3
> 
> ?- p(X,Y,D).
> X=21
> Y=13
> D=2 (<-just as an example)
> Yes.

Is D the sum of the deviations in X and Y or the maximum of them? 
Assuming that it is the sum:

ECLiPSe Constraint Logic Programming System [kernel]
Copyright Imperial College London and ICL
Certain libraries copyright Parc Technologies Ltd
GMP library copyright Free Software Foundation
Version 5.7 #25, Sun Dec 14 03:24 2003
[eclipse 1]: lib(ic).
ic_kernel.eco loaded traceable 0 bytes in 0.02 seconds
linearize.eco loaded traceable 0 bytes in 0.02 seconds
ordset.eco loaded traceable 0 bytes in 0.01 seconds
ic_constraints.eco loaded traceable 0 bytes in 0.09 seconds
ic.eco     loaded traceable 0 bytes in 0.02 seconds
ic_generic_interface.eco loaded traceable 0 bytes in 0.01 seconds
ic_search.eco loaded traceable 0 bytes in 0.07 seconds
ic.eco     loaded traceable 0 bytes in 0.19 seconds
[eclipse 2]: [user].
  p(10,10).
  p(20,10).
  p(40,60).
  p(X, Y, D) :-
   get_var_bounds(D, _, Max),
   ic:([DX,DY] :: -Max .. Max),
   X + DX $= XTarget,
   Y + DY $= YTarget,
   D $= abs(DX) + abs(DY),
   p(XTarget, YTarget),
   indomain(D),
   indomain(X),
   indomain(Y).
  user       compiled traceable 1440 bytes in 0.01 seconds

Yes (0.01s cpu)
[eclipse 3]: [X,Y]::0..100,D::0..4,p(X,Y,D).

X = 10
Y = 10
D = 0
Yes (0.01s cpu, solution 1, maybe more) ? ;

...

X = 44
Y = 60
D = 4
Yes (0.11s cpu, solution 123)
[eclipse 4]:



-- 
Andrew Eremin
Research Assistant                   Tel: +44 (0)20 7594 8299
IC-Parc, Imperial College London     Fax: +44 (0)20 7594 8432
London SW7 2AZ                       Email: a.eremin@icparc.ic.ac.uk
Received on Tue Mar 09 14:43:06 2004

This archive was generated by hypermail 2.1.8 : Wed 16 Nov 2005 06:07:27 PM GMT GMT