[gecode-users] Views and serialization

Gustavo Gutierrez ggutierrez at cic.puj.edu.co
Fri Nov 23 22:18:38 CET 2007


Hi all,

I am working on merging a space SC in a S. For this to work i need to
create all actors available in SC into S. This is fine as the Space
class has method to return an iterator on space actors. I think the
following code will do the job (SC is the source and S is the target):

---- inside the queens class

 VarMap * exportVars(void) {
    VarMap *vmp = new VarMap();
    Support::Symbol symb("root",true);
    //vmp->registerArray(this,q,symb);
    vmp->putArray(this,q,symb);
    return vmp;
  }
----

--- outside the class
void merge(Queens *target, Queens *source) {
  // Print some useful information
  std::cout << "Number of propagators in trget " <<
target->propagators() << std::endl;
  std::cout << "Number of propagators in source " <<
source->propagators() << std::endl;

  // Ask source to build a Map of its variables
  VarMap *vmp = target->exportVars();

  // Create an iterator over home's actors
  Reflection::SpecIter si = source->actorSpecs(*vmp);

  Gecode::Serialization::Deserializer *ds = new Deserializer(target, *vmp);

  while (si()) {
    ds->post(si.actor());
    ++si;
  }

  // Test the number of actors in target
  std::cout << "Number of propagators in trget " <<
target->propagators() << std::endl;
}
----

Is it right or did i miss something?


The other step is to create all variables in SC in S. For this part i
have reading the documenttion and found that IntView and SetView
classes have a method called spec that returns an specification of a
variable. For the Queens problem this would be fine as all variables
are IntVars so creating IntView is easy. The problem raises when i
have a collection of variables of different types (an array of
VarBase*) and need to get the specification for each one. Is there any
way to do this?. Note that i don't know each variable's type so
creating the corresponding view is not possible.

I prefer to ask this before doing some changes to my design, so sorry
if my question sounds a little lazy.By the way, is there some example
that use space serialization or reflection mechanisms?

Thanks in advance,

-- 
Gustavo Gutierrez




More information about the gecode-users mailing list