Example #1
0
void PPLMGeneralComparison::do_next (xqp_tuple &t)
{
 	if (first_time)
    {
		first_time = false;
		tuple_cell (*comp_op) (const tuple_cell&,const tuple_cell&,CollationHandler*);
		if (strict)
		{
			if (more)
				comp_op=op_gt;
			else
				comp_op=op_lt;
		}
		else
		{
			if (more)
				comp_op=op_ge;
			else
				comp_op=op_le;
		}
		//INSERT CODE HERE
		if (!eos_reached1) seq1.op->reopen();
		if (!eos_reached2) seq2.op->reopen();
		eos_reached2 = false;
		eos_reached1 = false;
		xqp_tuple cont1(seq1.ts);
		xqp_tuple cont2(seq2.ts);
		seq1.op->next(cont1);
		sequence seq(1);
		xqp_tuple at_tup(1);
		seq2.op->next(cont2);
		if (cont2.is_eos())
		{
			eos_reached2 = true;
			t.copy(tuple_cell::atomic(false));
			return;
		}
		tuple_cell res1=getAtomizedCell(cont2);
		while (!cont1.is_eos())
		{
			tuple_cell res=getAtomizedCell(cont1);
			at_tup.cells[0]=res;
			generalNodePrepare(res,res1);
			if (comp_op(res,res1,handler).get_xs_boolean())
			{
				t.copy(tuple_cell::atomic(true));
				return;
			}
			seq.add(at_tup);
			seq1.op->next(cont1);
		}
		eos_reached1 = true;
		if (seq.size()<1)
		{
			t.copy(tuple_cell::atomic(false));
			return;
		}
		seq2.op->next(cont2);
		while (!cont2.is_eos())
		{
			tuple_cell res1=getAtomizedCell(cont2);
			sequence::iterator it=seq.begin();
			do
			{
				tuple_cell res2=(*it).cells[0];
				generalNodePrepare(res1,res2);
				if (comp_op(res2,res1,handler).get_xs_boolean())
				{
					t.copy(tuple_cell::atomic(true));
					return;
				}
				it++;
			}
			while (it!=seq.end());
			seq2.op->next(cont2);
		}
		eos_reached2 = true;
		t.copy(tuple_cell::atomic(false));
		return;

	}
	else 
    {
        first_time = true;
        t.set_eos();
    }
}
Example #2
0
int main (int __argc, char *__argv[])
{
  peo :: init( __argc, __argv );
  if (getNodeRank()==1)
    std::cout<<"\n\nTest : PSO Global Best\n\n";
  rng.reseed (10);
  RingTopology topologyMig;
  eoGenContinue < Indi > genContPara (10);
  eoCombinedContinue <Indi> continuatorPara (genContPara);
  eoCheckPoint<Indi> checkpoint(continuatorPara);
  peoEvalFunc<Indi, double, const Indi& > plainEval(f);
  peoPopEval< Indi > eval(plainEval);
  eoUniformGenerator < double >uGen (0, 1.);
  eoInitFixedLength < Indi > random (2, uGen);
  eoUniformGenerator < double >sGen (-1., 1.);
  eoVelocityInitFixedLength < Indi > veloRandom (2, sGen);
  eoFirstIsBestInit < Indi > localInit;
  eoRealVectorBounds bndsFlight(2,0,1.);
  eoStandardFlight < Indi > flight(bndsFlight);
  eoPop < Indi > pop;
  pop.append (10, random);
  eoLinearTopology<Indi> topology(2);
  eoRealVectorBounds bnds(2,-1.,1.);
  eoStandardVelocity < Indi > velocity (topology,1,0.5,2.,bnds);
  eoInitializer <Indi> init(eval,veloRandom,localInit,topology,pop);
  eoPeriodicContinue< Indi > mig_cont( 2 );
  peoPSOSelect<Indi> mig_selec(topology);
  peoGlobalBestVelocity<Indi> mig_replac (2.,velocity);
  eoContinuator<Indi> cont(mig_cont, pop);
  eoSelector <Indi, eoPop<Indi> > mig_select (mig_selec,1,pop);
  eoReplace <Indi, eoPop<Indi> > mig_replace (mig_replac,pop);
  eoGenContinue < Indi > genContPara2 (10);
  eoCombinedContinue <Indi> continuatorPara2 (genContPara2);
  eoCheckPoint<Indi> checkpoint2(continuatorPara2);
  peoEvalFunc<Indi, double, const Indi& > plainEval2(f);
  peoPopEval< Indi > eval2(plainEval2);
  eoUniformGenerator < double >uGen2 (0, 1.);
  eoInitFixedLength < Indi > random2 (2, uGen2);
  eoUniformGenerator < double >sGen2 (-1., 1.);
  eoVelocityInitFixedLength < Indi > veloRandom2 (2, sGen2);
  eoFirstIsBestInit < Indi > localInit2;
  eoRealVectorBounds bndsFlight2(2,0,1.);
  eoStandardFlight < Indi > flight2(bndsFlight2);
  eoPop < Indi > pop2;
  pop2.append (10, random2);
  eoLinearTopology<Indi> topology2(2);
  eoRealVectorBounds bnds2(2,-1.,1.);
  eoStandardVelocity < Indi > velocity2 (topology2,1,0.5,2.,bnds2);
  eoInitializer <Indi> init2(eval2,veloRandom2,localInit2,topology2,pop2);
  eoPeriodicContinue< Indi > mig_cont2( 2 );
  peoPSOSelect<Indi> mig_selec2(topology2);
  peoGlobalBestVelocity<Indi> mig_replac2 (2.,velocity2);
  eoContinuator<Indi> cont2(mig_cont2,pop2);
  eoSelector <Indi, eoPop<Indi> > mig_select2 (mig_selec2,1,pop2);
  eoReplace <Indi, eoPop<Indi> > mig_replace2 (mig_replac2,pop2);
  peoAsyncIslandMig< eoPop<Indi>, eoPop<Indi> > mig(cont,mig_select, mig_replace, topologyMig);
  checkpoint.add( mig );
  peoAsyncIslandMig< eoPop<Indi>, eoPop<Indi> > mig2(cont2,mig_select2, mig_replace2, topologyMig);
  checkpoint2.add( mig2 );
  eoSyncEasyPSO <Indi> psa(init,checkpoint,eval, velocity, flight);
  peoWrapper parallelPSO( psa, pop);
  eval.setOwner(parallelPSO);
  mig.setOwner(parallelPSO);
  eoSyncEasyPSO <Indi> psa2(init2,checkpoint2,eval2, velocity2, flight2);
  peoWrapper parallelPSO2( psa2, pop2);
  eval2.setOwner(parallelPSO2);
  mig2.setOwner(parallelPSO2);
  peo :: run();
  peo :: finalize();
  if (getNodeRank()==1)
    {
      pop.sort();
      pop2.sort();
      std::cout << "Final population :\n" << pop << std::endl;
      std::cout << "Final population :\n" << pop2	 << std::endl;
    }
}
Example #3
0
void PPNEQGeneralComparison::do_next (xqp_tuple &t)
{
	if (first_time)
    {
        first_time = false;
		if (!eos_reached1) seq1.op->reopen();
		if (!eos_reached2) seq2.op->reopen();
		eos_reached2 = false;
		eos_reached1 = false;
		xqp_tuple cont1(seq1.ts);
		xqp_tuple cont2(seq2.ts);
		xqp_tuple * cont[2]={&cont1,&cont2};
		PPOpIn * seq[2]={&seq1,&seq2};
		bool seq_end[2]={false,false};
		bool two_diffs_exist[2]={false,false};
		bool uv_exist[2]={false,false};
		bool switcher=true;
		tuple_cell seq_str_val[2];
		seq[0]->op->next(*cont[0]);
		if ((*cont[0]).is_eos())
		{
			eos_reached1 = true;
			t.copy(tuple_cell::atomic(false));
			return;
		}
		seq[1]->op->next(*cont[1]);
		if ((*cont[1]).is_eos())
		{
			eos_reached2 = true;
			t.copy(tuple_cell::atomic(false));
			return;
		}
		tuple_cell res[2];
		res[0]=getAtomizedCell(*cont[0]);
		if (res[0].get_atomic_type()==xs_untypedAtomic) 
		{
			seq_str_val[0]=res[0];
			uv_exist[0]=true;
		}
		res[1]=getAtomizedCell(*cont[1]);
		if (res[1].get_atomic_type()==xs_untypedAtomic) 
		{
			seq_str_val[1]=res[1];
			uv_exist[1]=true;
		}
		generalNodePrepare(res[0],res[1]);
		if (op_ne(res[0],res[1],handler).get_xs_boolean())
		{
			t.copy(tuple_cell::atomic(true));
			return;
		}
		int pr=0;
		while(true)
		{
			(switcher)?pr=0:pr=1;
			switcher=!switcher;
			if (!seq_end[pr] )
			{
				seq[pr]->op->next(*cont[pr]);
				if (cont[pr]->is_eos())
				{
					(pr==0)? eos_reached1 = true: eos_reached2 = true;
					seq_end[pr]=true;
					if (seq_end[1-pr])
					{
						t.copy(tuple_cell::atomic(false));
						return;
					}
				}
				else
				{
					res[pr]=getAtomizedCell(*cont[pr]);
					if (res[pr].get_atomic_type()==xs_untypedAtomic) 
					{
						if (!uv_exist[pr])
						{
							seq_str_val[pr]=res[pr];
							uv_exist[pr]=true;
						}
						else
						{
							if (op_ne(cast(seq_str_val[pr], xs_string),cast(res[pr], xs_string),handler).get_xs_boolean())
								two_diffs_exist[pr]=true;
						}
						if (
							(two_diffs_exist[pr]&& uv_exist[1-pr])||
							(two_diffs_exist[1-pr]&& uv_exist[pr])
							)
						{
							t.copy(tuple_cell::atomic(true));
							return;
						}
						if (uv_exist[1-pr])
						{
							if (op_ne(cast(seq_str_val[pr], xs_string),cast(seq_str_val[1-pr], xs_string),handler).get_xs_boolean())
							{
								t.copy(tuple_cell::atomic(true));
							    return;
							}
						}
					}
					generalNodePrepare(res[0],res[1]);
					if (op_ne(res[0],res[1],handler).get_xs_boolean())
					{
						t.copy(tuple_cell::atomic(true));
						return;
					}
				}
			}
		}
	}
	else 
    {
        first_time = true;
        t.set_eos();
    }
}