예제 #1
0
bool
CSPold::performMoving(unsigned int boxesId, int x, int y, vector<unsigned int>& movedBoxes, unsigned int maxModification)
{
	int *varsIDs = new int[3];
	unsigned int *values = new unsigned int[3];


	//ConstrainedBox* box = (ConstrainedBox*)(*_cedEntities)[boxesId];
	ConstrainedBox* box = getBoxById(boxesId);

	varsIDs[0] = box->getFirstControlPoint()->beginID();
	values[0] = x;

	// maxSceneWidth = mother's length
	int maxSceneWidth = box->getFirstControlPoint()->getBeginMax();

	varsIDs[1] = box->getLastControlPoint()->beginID();
	values[1] = y;

	varsIDs[2] = box->lengthID();
	values[2] = y - x;

	for (int i = 0; i < 3 ; ++i) {
		if (values[i] < 1) {
			values[i] = 1;
		} else if (values[i] > maxSceneWidth) {
			values[i] = maxSceneWidth;
		}
	}


	bool validSolution = _solver->suggestValues(varsIDs, values, 3, maxModification);

	delete[] varsIDs;
	delete[] values;

	movedBoxes.clear();
	if (validSolution) {
		updateFromSolver(); //TODO: la clef est ici !!!

		map<unsigned int, ConstrainedTemporalEntity*>::iterator it  = _cedEntities->begin();
		while (it != _cedEntities->end())
		{
			movedBoxes.push_back(it->first);
			it++;
		}

		return true;
	} else {
		return false;
	}
}
예제 #2
0
void CSPold::changeAllBoxMaxSceneWidth(int newValue)
{
	map<unsigned int, ConstrainedTemporalEntity*>::iterator it  = _cedEntities->begin();
	while (it != _cedEntities->end())
	{
		ConstrainedBox* currentBox = (ConstrainedBox*) it->second;

		currentBox->changeMax(_solver, newValue);
		currentBox->getFirstControlPoint()->changeMax(_solver, newValue);
		currentBox->getLastControlPoint()->changeMax(_solver, newValue);

		it++;
	}
}
예제 #3
0
unsigned int
CSPold::addBox(unsigned int boxId, int boxBeginPos, int boxLength, unsigned int motherId, int maxSceneWidth)
{

	// Vérification de la non existence de boxId
	map<unsigned int, ConstrainedTemporalEntity *>::iterator iter = (*_cedEntities).find(boxId);
	if(iter != (*_cedEntities).end())  {
		throw IllegalArgumentException();
	}

	// Création dans le solver et dans le CSP des valeurs de début et de taille de la boite
	CSPConstrainedVariable *begin = new CSPConstrainedVariable(_solver->addIntVar(1, maxSceneWidth, boxBeginPos, (int)BEGIN_VAR_TYPE),
			1, maxSceneWidth, boxBeginPos, BEGIN_VAR_TYPE);
	CSPConstrainedVariable *length = new CSPConstrainedVariable(_solver->addIntVar(10, maxSceneWidth, (int)boxLength, (int)LENGTH_VAR_TYPE),
			10, maxSceneWidth, (int)boxLength, LENGTH_VAR_TYPE);

	// Création de la boite
	ConstrainedBox *newBox = new ConstrainedBox(begin, length);

	// Création dans le solver et dans le CSP des valeurs du ControlPoint de fin de la boite
	CSPConstrainedVariable *CP2begin = new CSPConstrainedVariable(_solver->addIntVar(1, maxSceneWidth, boxBeginPos + boxLength, (int)BEGIN_VAR_TYPE),
			1, maxSceneWidth, boxBeginPos + boxLength, BEGIN_VAR_TYPE);
	CSPConstrainedVariable *CP2length = new CSPConstrainedVariable(_solver->addIntVar(0, maxSceneWidth, 0, (int)LENGTH_VAR_TYPE),
			0, maxSceneWidth, 0, LENGTH_VAR_TYPE);

	// Création et ajout dans la boite d'un CP équivalent à la boite et d'un autre à la fin
	newBox->addControlPoint(new ControlPoint(begin, length, boxId), BEGIN_CONTROL_POINT_INDEX);
	newBox->addControlPoint(new ControlPoint(CP2begin, CP2length, boxId), END_CONTROL_POINT_INDEX);

	// Ajout de la relation entre la boite et sa fin
	addAllenRelation(newBox->getLastControlPoint(), newBox, ALLEN_FINISHES, false);

	// ??
	newBox->getFirstControlPoint()->setProcessStepId(1);
	newBox->getLastControlPoint()->setProcessStepId(2);

	if (motherId != NO_ID) {
//		ConstrainedBox* mother = getBoxById(motherId);
//		newBox->setMother(mother);
//		mother->addChild(newBox);
	}

	(*_cedEntities)[boxId] = newBox;
	newBox->setId(boxId);

	//changeAllBoxMaxSceneWidth(10000);

	return newBox->getId();
}