예제 #1
0
void
CSPold::updateFromSolver()
{
	map<unsigned int, ConstrainedTemporalEntity*>::iterator it  = _cedEntities->begin();

	while (it != _cedEntities->end())
	{
		ConstrainedBox* constrainedBox = (ConstrainedBox*) it->second;

		vector<CSPConstrainedVariable*> *vars = constrainedBox->variables();
		for (unsigned int v = 0; v<vars->size(); v++) {
			vars->at(v)->setValue(_solver->getVariableValue(vars->at(v)->getID()));
		}

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

		for (unsigned int j = 0 ; j < controlPointID->size() ; ++j)
		{
			ControlPoint* controlPoint = constrainedBox->getControlPoint(controlPointID->at(j));

			vector<CSPConstrainedVariable*> *varsControl = controlPoint->variables();

			for (unsigned int v = 0; v<varsControl->size(); v++) {
				varsControl->at(v)->setValue(_solver->getVariableValue(varsControl->at(v)->getID()));

			}
		}
		it++;
		delete vars;
	}

//	for (unsigned int i=0; i<_temporalRelations->size(); i++) {
//		if (dynamic_cast<IntervalRelation*>(_temporalRelations->at(i))) {
//			_solver->getVariableValue( dynamic_cast<IntervalRelation*>(_temporalRelations->at(i))->varID());
//			_solver->getVariableValue(_temporalRelations->at(i)->entity2()->beginID());
//			_solver->getVariableValue(_temporalRelations->at(i)->entity1()->beginID());
//			_solver->getVariableValue(_temporalRelations->at(i)->entity1()->lengthID());
//		}
//	}
}
예제 #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);
}