Esempio n. 1
0
void
MMO_Expression_::_addDeps (Dependencies deps, DEP_Type type, Index index)
{
  DEP_Type vectorType = DEP_STATE_VECTOR;
  if (type == DEP_DISCRETE)
    {
      vectorType = DEP_DISCRETE_VECTOR;
    }
  else if (type == DEP_ALGEBRAIC)
    {
      vectorType = DEP_ALGEBRAIC_VECTOR;
    }
  for (Index *idx = deps->begin (type); !deps->end (type);
      idx = deps->next (type))
    {
      Index dIdx (*idx);
      if (dIdx.hasRange ())
	{
	  // TODO: Agregar las dependencias vectoriales con el rango correcto cuando no
	  // estan definidas en el mismo rango que la discreta.
	  Index vi (index);
	  vi.setOffset (dIdx.offset ());
	  _deps->insert (vi, vectorType);
	}
      else
	{
	  _deps->insert (dIdx, type);
	}
    }
}
Esempio n. 2
0
long ConditionsMappedUserPool<MAPPING>::compute(const Dependencies& deps, void* user_param)  {
  long num_updates = 0;
  if ( !deps.empty() )  {
    typedef Dependencies _D;
    ConditionsDependencyHandler handler(m_manager.ptr(), *this, deps, user_param);
    ConditionsPool* pool = m_manager->registerIOV(*m_iov.iovType, m_iov.keyData);
    // Loop over the dependencies and check if they have to be upgraded
    for(_D::const_iterator i = deps.begin(); i!=deps.end(); ++i)  {
      key_type key = (*i).first;
      typename MAPPING::iterator j = m_conditions.find(key);
      if ( j != m_conditions.end() )  {
        Condition::Object* cond = (*j).second;
        if ( IOV::key_is_contained(m_iov.keyData,cond->iov->keyData) )
          continue;
        /// This condition is no longer valid. remove it! Will be added again afterwards.
        m_conditions.erase(j);
      }
      const ConditionDependency* d = (*i).second.get();
      Condition::Object* cond = handler(d);
      m_manager->registerUnlocked(pool, cond); // Would bulk update be more efficient?
      ++num_updates;
    }
  }
  return num_updates;
}
Esempio n. 3
0
void JSONJob::execute()
{
    std::shared_ptr<Project> proj = project();
    const Path root = proj->path();
    const Dependencies deps = proj->dependencies();
    // error() << deps.keys();
    assert(proj);
    const SymbolMap &map = proj->symbols();
    write("{");
    bool firstObject = true;
    for (Dependencies::const_iterator it = deps.begin(); it != deps.end(); ++it) {
        const Path path = Location::path(it->first);
        if (path.startsWith(root) && (match.isEmpty() || match.match(path))) {
            const Location loc(it->first, 0);
            const int srcRootLength = project()->path().size();
            if (firstObject) {
                firstObject = false;
            } else {
                write(",");
            }
            write<64>("\"%s\":[", path.constData() + srcRootLength);
            bool firstSymbol = true;
            SymbolMap::const_iterator sit = map.lower_bound(loc);
            while (sit != map.end() && sit->first.fileId() == it->first) {
                Location targetLocation;
                SymbolInfo target = sit->second.bestTarget(map, 0, &targetLocation);
                const String type = sit->second.kindSpelling();
                if (firstSymbol) {
                    firstSymbol = false;
                } else {
                    write(",");
                }
                if (!targetLocation.isNull()) {
                    write<256>("{\"location\":%s,\"type\":\"%s\",\"target\":%s}",
                               toJSON(sit->first, it->first, sit->second.symbolLength, srcRootLength).constData(), type.constData(),
                               toJSON(targetLocation, it->first, target.symbolLength, srcRootLength).constData());
                } else {
                    write<256>("{\"location\":%s,\"type\":\"%s\"}",
                               toJSON(sit->first, it->first, sit->second.symbolLength, srcRootLength).constData(), type.constData());
                }

                ++sit;
            }
            write("]");
        }
    }
    write("}");
}
Esempio n. 4
0
void
MMO_Expression_::_traverseAlgebraics (Dependencies deps, Index derivativeIndex,
				      Dependencies derivativeDeps,
				      map<Index, Index> *states,
				      map<Index, Index> *discretes,
				      Index variableChange, DEP_Type type,
				      int value)
{
  for (Index *idx = deps->begin (type); !deps->end (type);
      idx = deps->next (type))
    {

      list<MMO_Equation> algEqs = _data->algebraics ()->equation (*idx);
      list<MMO_Equation>::iterator algEq;
      if (type == DEP_ALGEBRAIC_VECTOR_DEF)
	{
	  derivativeDeps->insert (*idx, DEP_ALGEBRAIC_VECTOR);
	}
      int algValue = -1;
      for (algEq = algEqs.begin (); algEq != algEqs.end (); algEq++)
	{
	  Index algebraicIdx = *idx;
	  if (value >= 0 && idx->hasRange ())
	    {
	      algebraicIdx = idx->indexValue (value);
	    }
	  if (!(*algEq)->exp()->deps()->autonomous())
	    {
	      _deps->setAutonomous(false);
	    }
	  Index variableCh;
	  int f = (*algEq)->lhs ().factor ();
	  int c = (*algEq)->lhs ().operConstant ();
	  if (f != 0 && type == DEP_ALGEBRAIC_DEF)
	    {
	      if (f != 1 || c != 0)
		{
		  variableCh.setFactor (f);
		  variableCh.setConstant (-c);
		  variableCh.setLow ((*algEq)->lhs ().low () * f + c);
		  variableCh.setHi ((*algEq)->lhs ().hi () * f + c);
		}
	    }
	  Index algebraicIndex = (*algEq)->lhs ();
	  if (variableChange.isSet ())
	    {
	      algebraicIndex = (*algEq)->lhs ().applyVariableChange (
		  variableChange);
	      algebraicIdx = idx->applyVariableChange (variableChange);
	      algebraicIdx.setLow (variableChange.low ());
	      algebraicIdx.setHi (variableChange.hi ());
	    }
	  Intersection is = algebraicIndex.intersection (algebraicIdx);
	  if (is.type () != IDX_DISJOINT)
	    {
	      Index algKey = algebraicIdx;
	      Index equationIndex;
	      equationIndex.setOffset (_equationIndex++);
	      if (is.hasRange ())
		{
		  equationIndex.setRange ();
		  equationIndex.setLow (is.low ());
		  equationIndex.setHi (is.hi ());
		  algKey.setRange ();
		  algKey.setHi (equationIndex.hi ());
		  algKey.setLow (equationIndex.low ());
		}
	      else
		{
		  equationIndex.setConstant (is.modelicaValue ());
		  if (is.type () == IDX_CONSTANT_BA)
		    {
		      algKey.setConstant (is.modelicaValue () + is.begin ());
		      algValue = is.modelicaValue ();
		    }
		  else if (is.type () == IDX_CONSTANT_AB)
		    {
		      algKey.setConstant (is.modelicaValue () + is.begin ());
		      algValue = is.modelicaValue ();
		    }
		  else
		    {
		      algKey.setConstant (is.modelicaValue ());
		    }
		  algKey.setLow (1);
		  algKey.setHi (1);
		  algKey.setFactor (0);
		}
	      if (type == DEP_ALGEBRAIC_DEF)
		{
		  derivativeDeps->insert (algKey, DEP_ALGEBRAIC);
		}
	      _addAlgebriacDeps (algKey, (*algEq), equationIndex,
				 derivativeIndex, derivativeDeps, states,
				 discretes, variableCh, algValue);
	    }
	}
    }
}
Esempio n. 5
0
void
MMO_Expression_::_addAlgebriacDeps (Index algIndex, MMO_Equation equation,
				    Index equationIndex, Index derivativeIndex,
				    Dependencies derivativeDeps,
				    map<Index, Index> *states,
				    map<Index, Index> *discretes,
				    Index variableChange, int value)
{
  stringstream buffer;
  string indent;
  string variableString = equation->lhs ().variable (algIndex, "i");
  Dependencies deps = equation->exp ()->deps ();
  map<Index, Index> &stateVariables = *states;
  Index eqIndex = equationIndex;
  for (Index *idx = deps->begin (DEP_STATE); !deps->end (DEP_STATE);
      idx = deps->next (DEP_STATE))
    {
      if (stateVariables.find (*idx) == stateVariables.end ()
	  || equation->lhs ().variableChange (algIndex))
	{
	  Index stateIndex = Index (
	      idx->applyVariableChange (
		  equation->lhs ().variableIndex (algIndex)));
	  stateVariables[*idx] = *idx;
	  eqIndex.setOffset (_equationIndex++);
	  if (idx->hasRange () && eqIndex.hasRange ())
	    {
	      // X[i] = B[i];
	      derivativeDeps->insert (stateIndex, eqIndex, DEP_ALGEBRAIC_STATE);
	    }
	  else if (!idx->hasRange () && eqIndex.hasRange ())
	    {
	      // X[i] = B[N];
	      derivativeDeps->insert (stateIndex, eqIndex, DEP_ALGEBRAIC_STATE);
	    }
	  else if (idx->hasRange () && !eqIndex.hasRange ())
	    {
	      // X[N] = B[i];
	      if (derivativeIndex.hasRange ())
		{
		  Index newEqIndex = eqIndex;
		  newEqIndex.setRange ();
		  newEqIndex.setLow (derivativeIndex.low ());
		  newEqIndex.setHi (derivativeIndex.hi ());
		  derivativeDeps->insert (
		      stateIndex.indexValue (
			  stateIndex.value (algIndex.constant ())),
		      newEqIndex, DEP_ALGEBRAIC_STATE);
		}
	      else
		{
		  derivativeDeps->insert (
		      stateIndex.indexValue (
			  stateIndex.value (algIndex.constant ())),
		      eqIndex, DEP_ALGEBRAIC_STATE);
		}
	    }
	  else if (!idx->hasRange () && !eqIndex.hasRange ())
	    {
	      // X[N] = B[N];
	      if (derivativeIndex.hasRange () && !algIndex.isArray())
	     	{
	     	  Index newEqIndex = eqIndex;
	     	  newEqIndex.setRange ();
	     	  newEqIndex.setLow (derivativeIndex.low ());
	     	  newEqIndex.setHi (derivativeIndex.hi ());
	     	  derivativeDeps->insert (stateIndex,
	     	      newEqIndex, DEP_ALGEBRAIC_STATE);
	     	}
	      else
	     	{
	          derivativeDeps->insert (stateIndex, eqIndex, DEP_ALGEBRAIC_STATE);
	     	}

	    }
	}
    }
  map<Index, Index> &discreteVariables = *discretes;
  for (Index *idx = deps->begin (DEP_DISCRETE); !deps->end (DEP_DISCRETE); idx =
      deps->next (DEP_DISCRETE))
    {
      if (discreteVariables.find (*idx) == discreteVariables.end ()
	  || equation->lhs ().variableChange (algIndex))
	{
	  Index discreteIndex = Index (
	      idx->applyVariableChange (
		  equation->lhs ().variableIndex (algIndex)));
	  discreteVariables[*idx] = *idx;
	  eqIndex.setOffset (_equationIndex++);
	  if (idx->hasRange () && eqIndex.hasRange ())
	    {
	      // X[i] = B[i];
	      derivativeDeps->insert (discreteIndex, eqIndex,
				      DEP_ALGEBRAIC_DISCRETE);
	    }
	  else if (!idx->hasRange () && eqIndex.hasRange ())
	    {
	      // X[i] = B[N];
	      derivativeDeps->insert (discreteIndex, eqIndex,
				      DEP_ALGEBRAIC_DISCRETE);
	    }
	  else if (idx->hasRange () && !eqIndex.hasRange ())
	    {
	      // X[N] = B[i];
	      derivativeDeps->insert (
		  discreteIndex.indexValue (
		      discreteIndex.value (discreteIndex.constant ())),
		  eqIndex, DEP_ALGEBRAIC_DISCRETE);
	    }
	  else if (!idx->hasRange () && !eqIndex.hasRange ())
	    {
	      // X[N] = B[N];
	      derivativeDeps->insert (discreteIndex, eqIndex,
				      DEP_ALGEBRAIC_DISCRETE);
	    }
	}
    }
  for (Index *idx = deps->begin (DEP_STATE_VECTOR);
      !deps->end (DEP_STATE_VECTOR); idx = deps->next (DEP_STATE_VECTOR))
    {
      derivativeDeps->insert (*idx, DEP_STATE_VECTOR);
    }
  for (Index *idx = deps->begin (DEP_DISCRETE_VECTOR);
      !deps->end (DEP_DISCRETE_VECTOR); idx = deps->next (DEP_DISCRETE_VECTOR))
    {
      derivativeDeps->insert (*idx, DEP_DISCRETE_VECTOR);
    }
  _traverseAlgebraics (deps, derivativeIndex, derivativeDeps, states, discretes,
		       variableChange, DEP_ALGEBRAIC_DEF, value);
  _traverseAlgebraics (deps, derivativeIndex, derivativeDeps, states, discretes,
		       variableChange, DEP_ALGEBRAIC_VECTOR_DEF, value);
}