예제 #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::removeBox(unsigned int boxId, std::vector<unsigned int>& relationsRemoved, std::vector<unsigned int>& triggersRemoved)
{
	ConstrainedBox* cedBox = getBoxById(boxId);

	relationsRemoved.clear();
	triggersRemoved.clear();

	/*
     remove cedBox from the boxes hierarchy
	 */

//	for (vector<ConstrainedBox*>::iterator it = cedBox->children()->begin() ; it != cedBox->children()->end() ; it++)
//	{
//		removeBoundingRelation((*it)->boundingRelation());
//		(*it)->setMother(cedBox->mother(), addBoundingRelation(cedBox->mother(), (*it)));
//	}

	if (cedBox->mother())
	{
//		removeBoundingRelation(cedBox->boundingRelation());
//		cedBox->mother()->removeChild(cedBox);
	}

	/*
     remove temporal constraints implicating cedBox
	 */

	vector<BinaryTemporalRelation*> *relToRemove = links(cedBox);
	for (vector<BinaryTemporalRelation*>::iterator it = relToRemove->begin() ; it != relToRemove->end() ; it++)
	{
		unsigned int relationId = (*it)->getId();
		relationsRemoved.push_back(relationId);
		removeTemporalRelation((*it));
		delete (*it);
	}
	relToRemove->clear();
	delete relToRemove;

	vector<unsigned int>* controlPointID = new vector <unsigned int>;
	cedBox->getAllControlPointsId(controlPointID);

	for (unsigned int i = 0 ; i < controlPointID->size() ; ++i) {
		ControlPoint* currentControlPoint = cedBox->getControlPoint(controlPointID->at(i));

		if(currentControlPoint->getTriggerPoint() != NULL) {
			TriggerPoint* currentTriggerPoint = currentControlPoint->getTriggerPoint();
			triggersRemoved.push_back(currentTriggerPoint->getTriggerId());
			currentTriggerPoint->removeRelatedControlPoint();
		}

		relToRemove = links(currentControlPoint);
		for (vector<BinaryTemporalRelation*>::iterator it = relToRemove->begin() ; it != relToRemove->end() ; it++)
		{
			removeTemporalRelation((*it));
			delete (*it);
		}

		_solver->removeIntVar(currentControlPoint->beginID());
		_solver->removeIntVar(currentControlPoint->lengthID());
	}

	/*
    remove related variables from the solver
	 */

	_solver->removeIntVar(cedBox->beginID());
	_solver->removeIntVar(cedBox->lengthID());

	/*
    remove cedBox from the constrained objects' list of the CSPold
	 */

	_cedEntities->erase(boxId);
}