3

I can specify variable's domain in this way:

MyVar in 1..10

or

MyVar in {1,10,15}

but I have a variable which I would like to specify like this:

Activity_1__room in {room_1, room_2}  % i.e. as atoms not as integers

Is it possible to do it? Of course, it is possible to encode the names to integers but is it really necessary?

mat
  • 40,498
  • 3
  • 51
  • 78
MartyIX
  • 27,828
  • 29
  • 136
  • 207
  • Why do you need clpfd to manage this variable for you instead of just saying something like `room(room_1). room(room_2). ... room(Activity),` like one normally does when programming Prolog? You can't do arithmetic on `Activity_1__room` anyway. – Daniel Lyons May 09 '13 at 21:10
  • Well, I want to use `labeling` and I don't see how to use your code in labeling predicate. Maybe it is obvious but my knowledge of clpfd is very limited. I don't understand what is the border between prolog and clpfd library (i.e. how they internally work together). – MartyIX May 09 '13 at 21:28
  • I don't think there's any reason to use labeling for non-numeric values. If you make a fact for both rooms as I did above, and then use `room(ActivityRoom)` then the normal backtracking facilities will try each in turn until finding the right one. I suspect you are missing a lot of understanding about how Prolog works that you will need to address to make any real progress though. – Daniel Lyons May 09 '13 at 21:57
  • I also found that such automatic mapping from symbols to integer is sorely missing. Setting up 'zebra like' solvers it's a pain. I've done a silly library just to generate the boilerplate mapping names to variables (I could post, but it's for SWI). But I don't if could be of any utility during labeling. – CapelliC May 09 '13 at 22:01
  • 1
    Yes, CLP(FD) only works on integers, and I recommend you use the integers "1" and "2" instead of the atoms `room_1` and `room_2` in this case. You can introduce a mapping like `name_number(room_1, 1).` if you need it. It certainly makes sense to use CLP(FD) if you require disequalities etc. on rooms, since you can then use the built-in labeling strategies and do not have to write the search part yourself. – mat May 09 '13 at 23:17
  • @DanielLyons: actually, I consider it a deficiency in Sicstus (and SWI) that atoms cannot be used in CLP(FD). [ECLiPSe's](http://eclipseclp.org/) implementation does support them, so that working with finite sets becomes a lot easier. – Fred Foo May 10 '13 at 10:13
  • @larsmans I guess I just don't use it enough to see the need. – Daniel Lyons May 10 '13 at 14:07

1 Answers1

7

You can't use atoms. The domains in CLPFD range over integers.

But suppose that you want to say "MyVar should take one of the values of the list L", i.e. the set is not known a priori. This can be coded as:

?- list_to_fdset(L, Set),
   MyVar in_set Set.
MartyIX
  • 27,828
  • 29
  • 136
  • 207
Mats Carlsson
  • 1,426
  • 7
  • 3