Пример #1
0
  ExecStatus
  DistinctDoit<View0>::propagate(Space& home, const ModEventDelta&) {
    if (x0.assigned()) {
      GlbRanges<View0> xi(x0);
      GlbRanges<ConstSetView> yi(y);
      if (Iter::Ranges::equal(xi,yi)) { return ES_FAILED; }
      else { return home.ES_SUBSUMED(*this); }
    }
    assert(x0.lubSize()-x0.glbSize() >0);
    if (x0.cardMin()>y.cardMax()) { return home.ES_SUBSUMED(*this); }
    if (x0.cardMax()<y.cardMin()) { return home.ES_SUBSUMED(*this); }
    //These tests are too expensive, we should only do them
    //in the 1 unknown left case.
    GlbRanges<View0> xi1(x0);
    LubRanges<ConstSetView> yi1(y);
    if (!Iter::Ranges::subset(xi1,yi1)){ return home.ES_SUBSUMED(*this); }
    LubRanges<View0> xi2(x0);
    GlbRanges<ConstSetView> yi2(y);
    if (!Iter::Ranges::subset(yi2,xi2)){ return home.ES_SUBSUMED(*this); }
    // from here, we know y\subseteq lub(x) and glb(x)\subseteq y

    if (x0.lubSize() == y.cardMin() && x0.lubSize() > 0) {
      GECODE_ME_CHECK(x0.cardMax(home, x0.lubSize() - 1));
      return home.ES_SUBSUMED(*this);
    }
    if (x0.glbSize() == y.cardMin()) {
      GECODE_ME_CHECK(x0.cardMin(home, x0.glbSize() + 1));
      return home.ES_SUBSUMED(*this);
    }
    return ES_FIX;
  }
Пример #2
0
void make_sex()
{
   if (population.size() < psize)
     {
	cerr<<"Error | make_sex | internal error"<<endl;
	exit(EXIT_FAILURE);
     }
   size_t id1;
   size_t id2;
   do
     {
	id1 = random() % psize;
	id2 = random() % psize;	
     }
   while (id1 == id2);
   
   int ran = random() % (ansamble.size() + 1);
   
   
   
   cl_term* t1 = new cl_term(*(population[id1]->term));
   cl_term* t2 = new cl_term(*(population[id2]->term));
   vector<cl_term*> yi1(ansamble.size());
   vector<cl_term*> yi2(ansamble.size());
   for (size_t i = 0 ; i < ansamble.size() ; i++)
     {
	yi1[i] = new cl_term(*(population[id1]->yi[i]));
	yi2[i] = new cl_term(*(population[id2]->yi[i]));
     }
   
   if (ran == (int)ansamble.size()) //make sex between terms   
     {	
	if (crossover_type == 0)
	  t1->crossover_a(t2);     
	else if (crossover_type == 1)
	  t1->crossover_s1(t2);
	else
	  {
	     cerr<<"Error | make_sex | unknown crossover type"<<endl;
	     exit(EXIT_FAILURE);
	  }
        
	if (p_exchange_mutation > 0)
	  {
	     t1->exchange_mutation(p_exchange_mutation, alphabet);
	     t2->exchange_mutation(p_exchange_mutation, alphabet);
	  }
	
	if (p_trim_mutation > 0)
	  {
	     t1->trim_mutation(p_trim_mutation);
	     t2->trim_mutation(p_trim_mutation);
	  }
     } //end sex between terms
   else //make sex between yi[ran]
     {	
	if (crossover_type == 0)
	  yi1[ran]->crossover_a(yi2[ran]);     
	else if (crossover_type == 1)
	  yi1[ran]->crossover_s1(yi2[ran]);
	else
	  {
	     cerr<<"Error | make_sex | unknown crossover type"<<endl;
	     exit(EXIT_FAILURE);
	  }
        
	yi1[ran]->exchange_mutation(p_exchange_mutation, alphabet_yi);
	yi2[ran]->exchange_mutation(p_exchange_mutation, alphabet_yi);
	
	yi1[ran]->trim_mutation(p_trim_mutation);
	yi2[ran]->trim_mutation(p_trim_mutation);
     }
   
   vector<string> yi1_str(yi1.size());
   vector<string> yi2_str(yi2.size());
   
   for (size_t i = 0 ; i < yi1.size() ; i++)
     {
	yi1_str[i] = yi1[i]->conv2str();
	yi2_str[i] = yi2[i]->conv2str();
     }
   
   if (uniqchecker.try_to_add(t1->conv2str(), yi1_str))
     population.push_back(make_cl_rmdlga2_member(t1, yi1, yi1_str));
   else
     {
	delete t1;
	for (size_t i = 0 ; i < yi1.size() ; i++)
	  delete yi1[i];
     }
   if (uniqchecker.try_to_add(t2->conv2str(), yi2_str))
     population.push_back(make_cl_rmdlga2_member(t2, yi2, yi2_str));
   else
     {
	delete t2;
	for (size_t i = 0 ; i < yi2.size() ; i++)
	  delete yi2[i];
     }
}