Example #1
0
 void
 BElementExpr::post(Space& home, BoolVar b, bool pos, IntConLevel icl) {
   IntVar z = idx.post(home, icl);
   if (z.assigned() && z.val() >= 0 && z.val() < n) {
     BoolExpr be = pos ? (a[z.val()] == b) : (a[z.val()] == !b);
     be.rel(home,icl);
   } else {
     BoolVarArgs x(n);
     for (int i=n; i--;)
       x[i] = a[i].expr(home,icl);
     BoolVar res = pos ? b : (!b).expr(home,icl);
     element(home, x, z, res, icl);
   }
 }
Example #2
0
//************************* FUNCTION MakePrimeImplChart ************************
PrimeImplChart MakePrimeImplChart(BoolExpr minterms, BoolExpr prime_implicants) {
    /*
     * Receives: the inputted minterms for the expression to minimze
     * Task: Get the minimized expression of minterms
     * Returns: the essential primes as a BoolExpr
     */

    PrimeImplChart prime_impl_chart(prime_implicants.size(),
				    PrimeImplCol(minterms.size(), 0));

    // Mark the cells where the prime implicant is a subset of the minterm
    MarkSubsets(prime_impl_chart, minterms, prime_implicants);

    return prime_impl_chart;
}
Example #3
0
//************************* FUNCTION FindPrimeImplicants ***********************
BoolExpr FindPrimeImplicants(BoolExpr bool_expr) {

    /*
     * Receives: the inputted minterms for the expression to minimze
     * Task: Get the minimized expression of minterms
     * Returns: the essential primes as a BoolExpr
     */
    
    BoolExpr prime_implicants;
    
    do {
	// Sort the terms into groups based on their number of complements
	auto grouped_terms = BucketSortTerms(bool_expr);
	//std::cout << PrintTermBuckets(grouped_terms) << std::endl;
	// Compare the groups with each other to reduce the terms
	auto terms_pair = CompareTermBuckets(grouped_terms);

	// bool_expr will contain the terms that will be sorted into buckets
	// next iteration (if there are still terms to compare)
	bool_expr = terms_pair.first;
	
	// Concatenate the unused terms to the list of prime implicants to return
	prime_implicants = CombineBoolExprs(prime_implicants, terms_pair.second);

	// Continue while there are still terms to compare
    } while (bool_expr.size());

    // Return the list of prime implicants
    return prime_implicants;
}
Example #4
0
void IRGenerator::accept(BoolExpr& literal)
{
    FNTRACE();

    // loads a boolean literal

    result_ = get(int64_t(literal.value()));
}
Example #5
0
//************************* FUNCTION MarkSubsets *******************************
void MarkSubsets(PrimeImplChart &chart, BoolExpr &minterms,
		 BoolExpr &prime_implicants) {
    /*
     * Receives: the inputted minterms for the expression to minimze
     * Task: Get the minimized expression of minterms
     * Returns: the essential primes as a BoolExpr
     */

    int num_primes = prime_implicants.size();
    int num_minterms = minterms.size();
    
    // Compare each prime implicant to each minterm to see if it's a subset
    for (int i = 0; i < num_primes; ++i) {
	for (int j = 0; j < num_minterms; ++j) {
	    if (IsSubset(minterms[j], prime_implicants[i])) {
		chart[i][j] = 1;
	    }
	}
    }
}
Example #6
0
//************************* FUNCTION GetEssentialPrimes ************************
BoolExpr GetEssentialPrimes(PrimeImplChart &chart, BoolExpr &minterms,
			    BoolExpr &prime_implicants) {
    /*
     * Receives: the inputted minterms for the expression to minimze
     * Task: Get the minimized expression of minterms
     * Returns: the essential primes as a BoolExpr
     */

    int num_primes = prime_implicants.size();
    int num_minterms = minterms.size();

    BoolExpr essentials;

    // Check each column for a lone X; this means that this prime implicant
    // is essential; the expression cannot be built without it
    for (int minterm = 0; minterm < num_minterms; ++minterm) {
	int lone_position = -1;
	for (int prime = 0; prime < num_primes; ++prime) {
	    if (chart[prime][minterm] == 1) {
		// Check if there's been an X found already
		if (lone_position == -1) {
		    // Circle the X to mark the row as an essential PI
		    chart[prime][minterm] = 2;
		    // Save the location of the circled X
		    lone_position = prime;
		} else {
		    // Another X was found; uncircle the previous X
		    chart[lone_position][minterm] = 1;
		    // Reset lone_position to signify that there are multiple Xs
		    lone_position = -1;
		    // End search through this column
		    break;
		}
	    }
	}
	if (lone_position != -1) {
	    // This prime is essential; add it to essentials if it is not
	    // already added
	    auto essential_term = prime_implicants[lone_position];
	    bool not_added = true;
	    
	    for (auto term = essentials.begin(); term != essentials.end(); ++term) {
		if (*term == essential_term) {
		    not_added = false;
		    break;
		}
	    }
	    
	    if (not_added)
		essentials.push_back(essential_term);
	}
    }
    return essentials;
}
Example #7
0
 void ExprCompiler::visit(BoolExpr& expr, int dest)
 {
   write(expr, OP_BUILT_IN, expr.value() ? BUILT_IN_TRUE : BUILT_IN_FALSE,
         dest);
 }
Example #8
0
void* calc_thread(void* lpParam)
#endif
{
	using namespace mylib;
	thread_param* param = (thread_param*)lpParam;
	
	std::stringstream *sout = new std::stringstream;

	*sout << "#####################################" << std::endl;
	if(param->intern) *sout << "Внутренняя устойчивость, ";
	else *sout << "Внешняя устойчивость, ";
	*sout << param->p.name << ", " << param->size << "x" << param->size << std::endl;
	*sout << "#####################################" << std::endl << std::endl;

	*sout << "Матрица смежности" << std::endl;
	Matrix m(*(param->p.func),param->size);
	if(!param->intern)
		for(int i = 0; i < m.size(); i++)
			m[i][i]=true;
	*sout << m << endl;
	
	*sout << "Составление выражения по матрице:" << endl;
	if(param->intern)
	{
		BoolExpr expr(m,param->size);
		*sout << expr << endl;
		if(param->tmp_res)
		{
			*sout << "Приведение к ДНФ" << endl;
			expr.toDNF(&on_calc_step,sout);
		}
		else
			expr.toDNF(&on_calc_step);
		*sout << "ДНФ:" << endl;
		*sout << expr << endl;
		*sout << "Дополнения:\n";
		BoolExpr* cmpl = expr.getComplement();
		*sout << *cmpl << endl;
		*sout << "Число внутренней устойчивости:\n";
		*sout << cmpl->getMaxConjSize() << endl;
		*sout << "Расстановки с максимальным числом фигур" << endl;
		vector<vector<short> >* st = cmpl->getMaxConjs();
		for(int i = 0; i < st->size(); i++)
		{
			for(int j = 0; j < (*st)[i].size(); j++)
			{
				*sout << chess_pos(st->at(i).at(j),param->size) << " ";
			}
			*sout << endl;
		}
		delete st;
		delete cmpl;
	}
	else
	{
		BoolExprExt expr(m,param->size);
		*sout << expr << endl;
		if(param->tmp_res)
		{
			*sout << "Приведение к ДНФ:" << endl;
			expr.toDNF(sout,&on_calc_step);
			*sout << endl;
		}
		else
			expr.toDNF(NULL,&on_calc_step);
		*sout << "ДНФ:" << endl;
		*sout << expr << endl;
		*sout << "Число внешней устойчивости:" << endl;
		*sout << expr.getMinNumber() << endl;
		*sout << "Расстановки с минимальным числом фигур:" << endl;
		_bexpr *ms = expr.getMinSets();
		for(int i = 0; i < ms->size(); i++)
		{
			for(int j = 0; j < (*ms)[i].size(); j++)
			{
				*sout << chess_pos(ms->at(i).at(j),param->size) << " ";
			}
			*sout << endl;
		}
		delete ms;
	}

	delete param;

	Fl::awake(sout);

	return NULL;
}