Re: [eclipse-clp-users] multi-loop and if then statement

From: Joachim Schimpf <joachim.schimpf_at_...44...>
Date: Wed, 09 Sep 2009 15:30:42 +1000
liu.yu.senior.china wrote:
> Dear Mr. Winterer,
>  
> Thank you so much. I understand and agree what you said. But it doesn't 
> work and I get a No. To debug, I first replace the line with 
> (1$=1)=>(1$=1). All the solutions of Fs are produced as expected. Then I 
> replace the line with (Fi $= Levels[J]) => (1 $= 1) and get a No.

Your Levels and Voltage variables are lists, not arrays, but you are
using subscripts to access their elements - this leads to the failure.
Instead of your for-loop, use a foreach-loop to iterate over the lists:

        (   foreach(V,Voltage),
            foreach(L,Levels),
            param(Fi,Vi)
        do
            Fi$=L => Vi$=V
        )


By the way, if your levels are always 1..M, and the voltages are
integers, then you can replace the loop with the single constraint

        element(Fi, Voltage, Vi)


-- Joachim
Received on Wed Sep 09 2009 - 06:31:17 CEST

This archive was generated by hypermail 2.2.0 : Mon Jul 09 2018 - 02:05:29 CEST