[eclipse-clp-users] Dynamic List/ Array

From: Edgaonkar, Shrirang <Shrirang.Edgaonkar_at_...390...>
Date: Wed, 3 Dec 2014 07:58:48 +0000
Dear CLP users,





I have the following array. I need to know if we are able to insert new variables in the array or have constraints on the existing variables.

M = []([](2, 3, 5, _), [](1, 4, 7, _)),





After inserting new variables, the output should be as follows for example.

M = []([](2, 3, 5, _, 34), [](1, 4, 7, _, 87)),

34 and 87 have no relation with existing data in array. They are just hard coded numbers.





The following is the way I need to add the constraint for the array.

M[1, 4] + M[2, 4] #= 10,



%Search API to solve the above constraint..



and provide solution as

M = []([](2, 3, 5, 2, 34), [](1, 4, 7, 8, 87)),



Please let me know if this is possible.



I have tried and understood about list/array.

Following are some of my samples. They have nothing to do with my question in particular.

:-lib(ic).

:- local struct( others(dvds, ratings) ).
:- local struct( see(others, stars) ).
:- local struct( book(author, title, year, publisher, cost, details, see) ).

top(M):-


  M = []([](2, 3, 5, _), [](1, 4, 7, _)),
  A is M[1, 2] + M[2, 3],
  % Reading from array
  writeln("Reading from array"),
  writeln(A),


  B #= 2,

  D is M[B, 2] + M[2, 3],
  % Reading from array with index as variable
  writeln("Reading from array with index as variable"),
  writeln(D),

  E is M[B, 2] * M[2, 3],
  % Reading from array with arithmetic operation
  writeln("Reading from array with arithmetic operation"),
  writeln(E),

  % Reading from array with arithmetic operation
  writeln("Reading from array with arithmetic operation"),
  writeln(M[B, 2]),

  M[1,4] #= 5,
  writeln("Writing to array"),
  writeln(M[1,4]),

  %writeln("Modifying existing array"),
  %writeln(M[1,1]),

  writeln("Reading from list  and inserting in a new list with arithmetic operation"),
 ( foreach(X,[1,2,3]), foreach(Y,List) do Y is X + 3 ),
  writeln(List),

   ( foreach(List,[1]), foreach(Y,List) do Y is X + 3 ),
  writeln(List).



Thanks and Regards,

Shrirang Edgaonkar









________________________________
From: Edgaonkar, Shrirang
Sent: 21 November 2014 10:05:36
To: eclipse-clp-users_at_...105...
Subject:


Dear Eclipse users group,



  I am working on solving constraints based on real numbers. Following is the sample code with all the constraints and locate API to find the solution.





:- module(test).
:- export hello/0.
:-lib(ic).

hello :-

  A :: -9223372036854775808.0__9223372036854775807.0,
  B :: -9223372036854775808.0__9223372036854775807.0,
  C :: -9223372036854775808.0__9223372036854775807.0,
  D :: -9223372036854775808.0__9223372036854775807.0,

  A $> B,
  B $< C,
  B + C $= 78,
  ((D - B) * 45) / A $= 123.35,

  locate([A, B, C, D], 1e-1, lin),

  writeln(a=[A]),
  writeln(b=[B]),
  writeln(c=[C]),
  writeln(d=[D]),
  writeln("%%%%%%%%%%%%%%%%%%%%%%%%%").







Following is the output but the output is always in ranges and I need solution that is a single set of real numbers. Please help me on how can I achieve this.





Output



a = [_436{16.8253096002924 .. 17.8537558438417}]
b = [_575{16.8253096002924 .. 17.8537558438417}]
c = [_714{60.1462441561583 .. 61.1746903997076}]
d = [_853{62.9453526935382 .. 66.7928843624611}]
%%%%%%%%%%%%%%%%%%%%%%%%%





Thanks and Regards,

Shrirang Edgaonkar

______________________________________________________________________
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 Wed Dec 03 2014 - 08:20:07 CET

This archive was generated by hypermail 2.3.0 : Tue Apr 16 2024 - 09:13:20 CEST