Exemplo n.º 1
0
Scheme Relation::join_scheme(Relation r2) {
	Scheme s = Scheme();

	// Put in the whole first scheme
	for (auto var : this->scheme)
		s.push_back(var);

	// Put in any additional vars from the second scheme
	for (auto var1 : this->scheme) {
		for (auto var2 : r2.scheme) {
			if (std::find(s.begin(), s.end(), var2) == s.end()) {
				s.push_back(var2);
			}
		}
	}

	return s;
}
Scheme GtGenerator::generate(const TruthTable& table)
{
    n = 0;

    float time = 0;
    {
        AutoTimer timer(&time);

        checkPermutationValidity(table);
        tie(n, permutation) = getPermutation(table);
    }

    debugLog("GtGenerator::generate()-dump-permutation-creation-time", [=](ostream& out)->void
    {
        out << "Permutation creation time: ";
        out << setiosflags(ios::fixed) << setprecision(2) << time / 1000;
        out << " sec" << endl;
    });

    debugLog("GtGenerator::generate()-dump-permutation", [&](ostream& out)->void
    {
        out << "Permutation (non-fixed points number is " << permutation.getElementCount() << ")\n";
        out << permutation << endl;
    });

    Scheme scheme;
    if (permutation.length())
    {
        Scheme::iterator targetIter = scheme.end();

        shared_ptr<PartialGtGenerator> partialGenerator(new PartialGtGenerator());
        partialGenerator->setPermutation(permutation, n);
        partialGenerator->prepareForGeneration();

        while (partialGenerator)
            partialGenerator = reducePermutation(partialGenerator, n, &scheme, &targetIter);
    }

    return scheme;
}