Esempio n. 1
0
Clauses Term::getClauses(Assigment a) {
	Clauses cs;
	for (unsigned int i = 0; i < clauses.size(); i++)
	{
		Clause c;
		auto addClause = true;
		for (auto it : clauses[i])
		{
			auto var = abs(it);
			if (!a.isSet(var))
			{
				c.insert(it);
				continue;
			}
			if (it > 0 && a.isTrue(var) || it < 0 && a.isFalse(var))
			{
				addClause = false;
				break;
			}
			if (it > 0 && a.isFalse(var) || it < 0 && a.isTrue(var))
				continue;
			c.insert(it);
		}
		if (addClause)
			cs.push_back(c);
		else
		{
			c.clear();
			c.insert(0);
			cs.push_back(c);
		}
	}

	return cs;
}
Esempio n. 2
0
Clause Term::getClause(Assigment a, int i) {
	Clause c;
	auto addClause = true;
	for (auto it:clauses[i])
	{
		auto var = abs(it);
		if (!a.isSet(var))
		{
			c.insert(it);
			continue;
		}
		if (it > 0 && a.isTrue(var) || it < 0 && a.isFalse(var))
		{
			addClause = false;
			break;
		}
		else if (it > 0 && a.isFalse(var) || it < 0 && a.isTrue(var))
			continue;
		else
			c.insert(it);
	}
	if (addClause)
		return c;

	c.clear();
	c.insert(0);

	return c;
}
bool CNFGenerator::OnePersonOneTable()
{
	Clause onePersonAtLeastOneTable;
	Clause onePersonAtMaxOneTable;
	for (int i =0;i<people;i++)
	{
		onePersonAtLeastOneTable.clear();
		onePersonAtMaxOneTable.clear();
		//cout <<"atleast 1 =";
		for (int j=0;j<tables;j++)
		{
			Literal newLiteral(i,j,false);
			//cout <<newLiteral;
			onePersonAtLeastOneTable.insert(newLiteral);
			
		}
		//cout<<endl;

		//sort(onePersonAtLeastOneTable.begin(),onePersonAtLeastOneTable.end());
		SetOfClauses.insert(pair<Clause,int> (onePersonAtLeastOneTable,++CNFGenerator::globalClauseCount));
		
		for (int j=0;j<tables;j++)
		{
			for (int k=j+1;k<tables;k++)
			{
				onePersonAtMaxOneTable.clear();
				Literal newLiteral1(i,j,true);
				Literal newLiteral2(i,k,true);
				onePersonAtMaxOneTable.insert(newLiteral1);
				onePersonAtMaxOneTable.insert(newLiteral2);
				//sort(onePersonAtMaxOneTable.begin(),onePersonAtMaxOneTable.end());
				SetOfClauses.insert(pair<Clause,int> (onePersonAtMaxOneTable,++CNFGenerator::globalClauseCount));
			}
		}
		
	}

	return true;
}
Esempio n. 4
0
int
Semantic::getClauses(ombt::Set_List<Clause> &clist, Clause &c, 
	int storeClause, int negated, int concluded) const
{
	if (prep->getClauses(clist, c, 0, negated, concluded) != OK)
		return(NOTOK);
	if (storeClause && !c.isEmpty())
	{
		c.setPartOfConclusion(concluded);
		clist.insert(c);
		c.clear();
	}
	return(OK);
}
bool CNFGenerator::EnemiesGenerator()
{
	Clause newEnemyClause;
	for (vector<pair <short,short> >::iterator it = Enemies.begin();it!=Enemies.end();it++)
	{
		for (int i =0; i< tables;i++)
		{
			newEnemyClause.clear();
			Literal newLiteral1(it->first,i,true);
			Literal newLiteral2(it->second,i,true);
			newEnemyClause.insert(newLiteral1);
			newEnemyClause.insert(newLiteral2);
			//sort(newEnemyClause.begin(),newEnemyClause.end());
			SetOfClauses.insert(pair<Clause,int>(newEnemyClause,++CNFGenerator::globalClauseCount));
		}
		
	}

	return true;

}