std::set<BooleanFunction>::iterator it;
for(it=closure.begin (); it!=closure.end (); ++it)
{
std::set<BooleanFunction>::iterator jit;
for(jit=closure.begin (); jit!=closure.end (); ++jit)
{
for(uint i=0U; i<it->Arity (); ++i)
{ BooleanFunction f = it->Superposition (*jit, i);
if( f.Arity () <= test.Arity () )
closure.insert (f);
}
}
}
我如何确保每两个元素彼此具有叠加?
编辑:自我叠加也是可能的:f(f(x)),f(f(f(x))),... - 是的。
我认为你可以使用2套如下。
std::set<BooleanFunction> builder
std::set<BooleanFunction>::iterator it;
for(it=closure.begin (); it!=closure.end (); ++it)
{
bulider.insert(*it);
for(uint i=0U; i<it->Arity (); ++i)
{
BooleanFunction f = it->Superposition (*it, i);
if( f.Arity () <= test.Arity () )
builder.insert (f);
}
}
额外的循环体操看起来非常可怕:
void smart_insert (std::set<BooleanFunction> &closure,
std::set<BooleanFunction>::iterator it,
std::set<BooleanFunction>::iterator jit,
const BooleanFunction &f, uint arity)
{
if( f.Arity () <= arity && closure.find (f) == closure.end () )
{
if( f < *jit )
{ std::set<BooleanFunction>::iterator nit;
++it;
for(nit=closure.begin (); nit!=it; ++nit)
for(uint i=0U; i<nit->Arity (); ++i)
{ BooleanFunction ff = nit->Superposition (f, i);
smart_insert (closure, nit, closure.find (f), ff, arity);
} // end for i
} // end if *jit
if( f < *it )
{ std::set<BooleanFunction>::iterator njit;
++jit;
for(njit=closure.begin (); njit!=jit; ++njit)
for(uint i=0U; i<f.Arity (); ++i)
{ BooleanFunction ff = f.Superposition (*njit, i);
smart_insert (closure, closure.find (f), njit, ff, arity);
} // end for i
} // end if *it
closure.insert (f);
} // end if arity & unique
}
// ...
std::set<BooleanFunction>::iterator it;
for(it=closure.begin (); it!=closure.end (); ++it)
{
std::set<BooleanFunction>::iterator jit;
for(jit=closure.begin (); jit!=closure.end (); ++jit)
{
for(uint i=0U; i<it->Arity (); ++i)
{ BooleanFunction f = it->Superposition (*jit, i);
smart_insert (closure, it, jit, f, test.Arity () );
}
}
}