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; } }
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++; } }
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()); // } // } }
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(); }
unsigned int Editor::addBox(int boxBeginPos, int boxLength, unsigned int motherId) { if (motherId == NO_ID) { if (m_boxIdToContainingCSP.find(ROOT_BOX_ID) == m_boxIdToContainingCSP.end()) { m_mainCSP->addBox(m_nextBoxId, boxBeginPos, boxLength, motherId, boxLength); m_boxIdToContainingCSP[m_nextBoxId] = m_mainCSP; } else { return NO_ID; } } else { ConstrainedBox* motherBox = getBoxById(motherId); if ((boxBeginPos < motherBox->lengthValue()) && (boxBeginPos + boxLength) < motherBox->lengthValue()) { CSP* motherCSP = motherBox->getCSP(); motherCSP->addBox(m_nextBoxId, boxBeginPos, boxLength, motherId, motherBox->lengthValue()); m_boxIdToContainingCSP[m_nextBoxId] = motherCSP; motherCSP->getBoxById(m_nextBoxId)->setMother(motherBox); if (motherId != ROOT_BOX_ID) { if (motherBox->getHierarchyRelationId() == NO_ID) { std::vector<unsigned int> movedBox; unsigned int hierarchyRelation = addAntPostRelation(motherId, BEGIN_CONTROL_POINT_INDEX, motherId, END_CONTROL_POINT_INDEX, ANTPOST_ANTERIORITY, motherBox->lengthValue(), motherBox->lengthValue(), movedBox); motherBox->setHierarchyInformations(hierarchyRelation); } } } else { return NO_ID; } } ++m_nextBoxId; return (m_nextBoxId - 1); }
void Editor::removeBox(unsigned int boxId) { if (m_boxIdToContainingCSP.find(boxId) != m_boxIdToContainingCSP.end()) { CSP* containingCSP = m_boxIdToContainingCSP[boxId]; ConstrainedBox* currentBox = containingCSP->getBoxById(boxId); ConstrainedBox* mother = currentBox->mother(); std::vector<unsigned int> boxesId; std::vector<unsigned int> relationId; std::vector<unsigned int> triggerId; CSP* boxCSP = currentBox->getCSP(); if (boxCSP != NULL) { boxCSP->getAllBoxesId(boxesId); for (unsigned int i = 0; i < boxesId.size(); ++i) { removeBox(boxesId[i]); } } containingCSP->getAllBoxesId(boxesId); if (boxesId.size() == 0) { unsigned int motherHierarchyRelationId = mother->getHierarchyRelationId(); if (motherHierarchyRelationId != NO_ID) { if (m_boxIdToContainingCSP.find(mother->getId()) != m_boxIdToContainingCSP.end()) { CSP* motherCSP = m_boxIdToContainingCSP[mother->getId()]; motherCSP->removeTemporalRelation(motherHierarchyRelationId); } } } containingCSP->removeBox(boxId, relationId, triggerId); for (unsigned int i = 0; i < relationId.size(); ++i) { removeTemporalRelation(relationId[i]); } for (unsigned int i = 0; i < triggerId.size(); ++i) { removeTriggerPoint(triggerId[i]); } m_boxIdToContainingCSP.erase(boxId); } }
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); }
std::map<std::string, std::string> Editor::getOptionalArguments(unsigned int boxId) { ConstrainedBox* currentBox = getBoxById(boxId); return currentBox->getOptionalArguments(); }
void Editor::removeOptionalArgument(unsigned int boxId, std::string key) { ConstrainedBox* currentBox = getBoxById(boxId); currentBox->removeOptionalArgument(key); }
void Editor::setOptionalArgument(unsigned int boxId, std::string key, std::string value) { ConstrainedBox* currentBox = getBoxById(boxId); currentBox->setOptionalArgument(key, value); }
bool Editor::performMoving(unsigned int boxId, int x, int y, vector<unsigned int>& movedBoxes, int maxModification) { CSP* containingCSP = m_boxIdToContainingCSP[boxId]; ConstrainedBox* currentBox = containingCSP->getBoxById(boxId); ConstrainedBox* motherBox = currentBox->mother(); // if ((x > motherBox->lengthValue()) || (y > motherBox->lengthValue())) { // return false; // } containingCSP->changeAllBoxMaxSceneWidth(motherBox->lengthValue()); CSP* boxCSP = currentBox->getCSP(); int previousX = getBeginValue(boxId); int previousY = getEndValue(boxId); if (boxCSP != NULL) { std::vector<unsigned int> boxesId; boxCSP->getAllBoxesId(boxesId); if (boxesId.size() != 0) { unsigned int maxValue = 0; for (unsigned int i = 0; i < boxesId.size(); ++i) { unsigned int currentChildBoxEnd = boxCSP->getEndValue(boxesId[i]); if(currentChildBoxEnd > maxValue) { maxValue = currentChildBoxEnd; } } if ((unsigned int)(y - x) < maxValue) { return false; } } } int modificationX = abs(previousX - x); int modificationY = abs(previousY - y); if (maxModification < modificationX) { maxModification = modificationX; } if (maxModification < modificationY) { maxModification = modificationY; } unsigned int hierarchyRelation = currentBox->getHierarchyRelationId(); if (hierarchyRelation != NO_ID) { containingCSP->removeTemporalRelation(hierarchyRelation); } std::vector<unsigned int> hierarchyRelationMovedBoxes; if(containingCSP->performMoving(boxId, x, y, movedBoxes, maxModification)) { if (hierarchyRelation != NO_ID) { containingCSP->addAntPostRelation(hierarchyRelation, boxId, BEGIN_CONTROL_POINT_INDEX, boxId, END_CONTROL_POINT_INDEX, ANTPOST_ANTERIORITY, currentBox->lengthValue(), currentBox->lengthValue(), hierarchyRelationMovedBoxes, false); } movedBoxes.clear(); getAllBoxesId(movedBoxes); return true; } else { // put back the CSP into its previous state. containingCSP->performMoving(boxId, previousX, previousY, movedBoxes, maxModification); movedBoxes.clear(); getAllBoxesId(movedBoxes); return false; } }