Search the web
Sign In
New User? Sign Up
claireprogramminglanguage · Claire Programming Language - A place to discuss about the CLAIRE language
? Already a member? Sign in to Yahoo!

Yahoo! Groups Tips

Did you know...
Real people. Real stories. See how Yahoo! Groups impacts members worldwide.

Best of Y! Groups

   Check them out and nominate your group.
Having problems with message search? Fill out this form to ensure your group is one of the first to be migrated to the new message search system.

Messages

  Messages Help
Advanced
Tables   Message List  
Reply | Forward Message #581 of 1160 |
Re: Tables

I solved my problem. I discovered make_table and used that to write
the methods
[makePreferencesObjective(prob:choco/Problem): PreferencesObjective
-> // Seed the random number generator with the size of the problem
random!(length(prob.vars)),

// Generate the preferences for each variable and return the objective
let prefTable := make_table(choco/IntVar, table, nil)
in
( for var in prob.vars
( //prefTable[var] := makePreferenceList(var),
//self_print(prefTable[var] as list<integer>)
self_print(makePreferenceList(var))
),
PreferencesObjective(preferences = prefTable)
)
]

// Return a list with a random number between 0 and domain size less 1
for each value
// in the domain of the variable.
[makePreferenceList(var:choco/IntVar) : table
-> let scores := make_table(integer, integer, 0),
domainSize := choco/getDomainSize(var)
in
( printf("Generating preferences for variable ~S\n", var),
for val in choco/domainSet(var.choco/bucket)
( scores[val] := random(domainSize)
),
scores
)
]

Not quite as brief as the other ones but they do the job.

Another question, is it possible to get a list representation of the
range of a table. I tried to cast the table to a list but got a
segmentation fault.

Thanks,

Paidi

--- In claireprogramminglanguage@yahoogroups.com, "paidi_creed"
<paidi_creed@y...> wrote:
> Hi,
>
> I'm trying to implement an object representing an objective in a map
> colouring problem with a set of preferences for each colour at each
> node. I want to be able to have several objectives existing at the
> same time each with their own list of preferences.
>
> This requires a table[range = choco/IntVar, domain = table]
> and an inner table[range = integer, domain = integer]
>
> In the example for tables in the manual it uses
> square[x:(0 .. 20)] : integer := (x * x)
>
> this populates the table.
>
> Would it be possible to say
>
> [makePreferenceObjective(prob:choco/Problem) : PreferenceObjective
> -> preferenceTable[var:prob.vars] : table := makePreferenceList(var),
> PreferenceObjective(preferences = preferenceTable)
> ]
>
> where prob is the problem containing the variables to create a table
> mapping each variable in the problem to a table containing his
> preference for eahc value in that variables domain?
>
> Then can I write
>
> [makePreferenceList(var:choco/IntVar) : table
> -> scores[value: {set of values in the domain}] : integer :=
> random(choco/getDomainSize(var))
> ]
>
> to return a mapping from each value in the variables domain to a
> random number?
>
> When I try to run this I get error message the symbol var is unbound
> and if I just try to run makePreferenceList
> I get an error that value is unbound.
>
> I ran the example in the manual by typing it in to the interpreter and
> it worked fine.
> Am I doing something wrong when I use it inside my own methods.
>
> Thanks,
>
> Paidi




Thu Aug 14, 2003 7:45 pm

paidi_creed
Offline Offline
Send Email Send Email

Forward
Message #581 of 1160 |
Expand Messages Author Sort by Date

Hi, I'm trying to implement an object representing an objective in a map colouring problem with a set of preferences for each colour at each node. I want to be...
paidi_creed
Offline Send Email
Aug 14, 2003
6:33 pm

I solved my problem. I discovered make_table and used that to write the methods [makePreferencesObjective(prob:choco/Problem): PreferencesObjective -> // Seed...
paidi_creed
Offline Send Email
Aug 14, 2003
7:45 pm

... the ... Hi, a couple of things: (1) getting a seg fault is a bug. If you can isolate your code please report it as a bug (clairebugs@...) (unless you...
ycaseau
Online Now
Aug 22, 2003
4:10 am

... Thanks for the advice Yves. I don't think an array would do the job here, I'm using the table as a dictionary. Would it be better to use an array and a...
paidi_creed
Offline Send Email
Aug 22, 2003
5:56 pm
Advanced

Copyright © 2009 Yahoo! Inc. All rights reserved.
Privacy Policy - Terms of Service - Guidelines - Help