コード例 #1
0
ファイル: ConstraintTree.cpp プロジェクト: davidvaz/yap-udi
void
ConstraintTree::getTuples (
    CTNode* n, 
    Tuples currTuples,
    unsigned stopLevel,
    Tuples& tuplesCollected,
    CTNodes& continuationNodes) const
{
  if (n->isRoot() == false) {
    if (currTuples.size() == 0) {
        currTuples.push_back ({ n->symbol()});
    } else {
      for (size_t i = 0; i < currTuples.size(); i++) {
        currTuples[i].push_back (n->symbol());
      }
    }
    if (n->level() == stopLevel) {
      for (size_t i = 0; i < currTuples.size(); i++) {
        tuplesCollected.push_back (currTuples[i]);
        continuationNodes.push_back (n);
      }
      return;
    }
  }
  const CTChilds& childs = n->childs();
  for (CTChilds::const_iterator chIt = childs.begin();
      chIt != childs.end(); ++ chIt) {
    getTuples (*chIt, currTuples, stopLevel, tuplesCollected,
        continuationNodes);
  }
}
コード例 #2
0
ファイル: ConstraintTree.cpp プロジェクト: davidvaz/yap-udi
void
ConstraintTree::join (ConstraintTree* ct, bool oneTwoOne)
{
  if (logVarSet_.empty()) {
    CTNode::deleteSubtree (root_);
    root_      = CTNode::copySubtree (ct->root());
    logVars_   = ct->logVars();
    logVarSet_ = ct->logVarSet();
    return;
  }
  if (oneTwoOne) {
    if (logVarSet_.contains (ct->logVarSet())) {
      return;
    }
    if (ct->logVarSet().contains (logVarSet_)) {
      CTNode::deleteSubtree (root_);
      root_      = CTNode::copySubtree (ct->root());
      logVars_   = ct->logVars();
      logVarSet_ = ct->logVarSet();
      return;
    }
  }
  LogVarSet intersect = logVarSet_ & ct->logVarSet_;
  if (intersect.empty()) {
    // cartesian product
    appendOnBottom (root_, ct->root()->childs());
    Util::addToVector (logVars_, ct->logVars_);
    logVarSet_ |= ct->logVarSet_;
  } else {
    moveToTop (intersect.elements());
    ct->moveToTop (intersect.elements());
    
    Tuples tuples;
    CTNodes appendNodes;
    getTuples (ct->root(), Tuples(), intersect.size(),
        tuples, appendNodes);

    CTNodes::const_iterator appendIt = appendNodes.begin();
    for (size_t i = 0; i < tuples.size(); ++ i, ++ appendIt) {
      bool tupleFounded = join (root_, tuples[i], 0, *appendIt);
      if (oneTwoOne && tupleFounded == false) {
        assert (false);
      }
    }

    LogVars newLvs (ct->logVars().begin() + intersect.size(), 
                    ct->logVars().end());
    Util::addToVector (logVars_, newLvs);
    logVarSet_ |= LogVarSet (newLvs);
  }
}
コード例 #3
0
ファイル: ConstraintTree.cpp プロジェクト: davidvaz/yap-udi
ConstraintTree::ConstraintTree (
    const LogVars& logVars,
    const Tuples&  tuples)
{
  root_      = new CTNode (0, 0);
  logVars_   = logVars;
  logVarSet_ = LogVarSet (logVars);
  for (size_t i = 0; i < tuples.size(); i++) {
    addTuple (tuples[i]);
  }
}
コード例 #4
0
/**
 * @brief process Manipulates columns by adding the contents of thie record.
 *
 * Implematations should examine columns to determine the record history.
 */
void VeryLongStringRecord::process(SPSSImporter* importer, SPSSImportDataSet *dataset)
{
	SPSSImportDataSet::LongColsData strLengths;

	{
		Tuples strLens = breakNamePairs(_string_lengths);
		for (Tuples::const_iterator i = strLens.begin(); i != strLens.end(); i++)
			strLengths.insert(pair<string, size_t>(i->first, atol(i->second.c_str())));
	}
	dataset->veryLongColsDat(strLengths);

#ifdef JASP_DEBUG
//	DEBUG_COUT3("Found ", strLengths.size(), " tuples:");
//	for (map<string, size_t>::const_iterator i = strLengths.begin(); i != strLengths.end(); i++)
//	{
//		DEBUG_COUT5("... name = \"", i->first, "\" value = ", i->second, ".");
//	}
#endif

}
コード例 #5
0
ファイル: pyutils.cpp プロジェクト: cajal/cmt
Tuples PyList_AsTuples(PyObject* list) {
	if(!PyList_Check(list))
		throw Exception("Indices should be given in a list.");

	Tuples tuples;

	// convert list of tuples
	for(int i = 0; i < PyList_Size(list); ++i) {
		PyObject* tuple = PyList_GetItem(list, i);

		if(!PyTuple_Check(tuple) || PyTuple_Size(tuple) != 2)
			throw Exception("Indices should be stored in a list of 2-tuples.");

		int m, n;

		if(!PyArg_ParseTuple(tuple, "ii", &m, &n))
			throw Exception("Indices should be integers.");

		tuples.push_back(make_pair(m, n));
	}

	return tuples;
}
コード例 #6
0
ファイル: ConstraintTree.cpp プロジェクト: davidvaz/yap-udi
TupleSet
ConstraintTree::tupleSet (const LogVars& originalLvs)
{
  LogVars uniqueLvs;
  for (size_t i = 0; i < originalLvs.size(); i++) {
    if (Util::contains (uniqueLvs, originalLvs[i]) == false) {
      uniqueLvs.push_back (originalLvs[i]);
    }
  }

  Tuples tuples;
  moveToTop (uniqueLvs);
  unsigned stopLevel = uniqueLvs.size();
  getTuples (root_, Tuples(), stopLevel, tuples, CTNodes() = {});

  if (originalLvs.size() != uniqueLvs.size()) {
    vector<size_t> indexes;
    indexes.reserve (originalLvs.size());
    for (size_t i = 0; i < originalLvs.size(); i++) {
      indexes.push_back (Util::indexOf (uniqueLvs, originalLvs[i]));
    }
    Tuples tuples2;
    tuples2.reserve (tuples.size());
    for (size_t i = 0; i < tuples.size(); i++) {
      Tuple t;
      t.reserve (originalLvs.size());
      for (size_t j = 0; j < originalLvs.size(); j++) {
        t.push_back (tuples[i][indexes[j]]);
      }
      tuples2.push_back (t);
    }
    return TupleSet (tuples2);
  }

  return TupleSet (tuples);
}
コード例 #7
0
ファイル: HorusYap.cpp プロジェクト: davidvaz/yap-cmake
Parfactor*
readParfactor (YAP_Term pfTerm)
{
  // read dist id
  unsigned distId = YAP_IntOfTerm (YAP_ArgOfTerm (1, pfTerm));

  // read the ranges
  Ranges ranges;
  YAP_Term rangeList = YAP_ArgOfTerm (3, pfTerm);
  while (rangeList != YAP_TermNil()) {
    unsigned range = (unsigned) YAP_IntOfTerm (YAP_HeadOfTerm (rangeList));
    ranges.push_back (range);
    rangeList = YAP_TailOfTerm (rangeList);
  }

  // read parametric random vars
  ProbFormulas formulas;
  unsigned count = 0;
  unordered_map<YAP_Term, LogVar> lvMap;
  YAP_Term pvList = YAP_ArgOfTerm (2, pfTerm);
  while (pvList != YAP_TermNil()) {
    YAP_Term formulaTerm = YAP_HeadOfTerm (pvList);
    if (YAP_IsAtomTerm (formulaTerm)) {
      string name ((char*) YAP_AtomName (YAP_AtomOfTerm (formulaTerm)));
      Symbol functor = LiftedUtils::getSymbol (name);
      formulas.push_back (ProbFormula (functor, ranges[count]));
    } else {
      LogVars logVars;
      YAP_Functor yapFunctor = YAP_FunctorOfTerm (formulaTerm);
      string name ((char*) YAP_AtomName (YAP_NameOfFunctor (yapFunctor)));
      Symbol functor = LiftedUtils::getSymbol (name);
      unsigned arity = (unsigned) YAP_ArityOfFunctor (yapFunctor);
      for (unsigned i = 1; i <= arity; i++) {
        YAP_Term ti = YAP_ArgOfTerm (i, formulaTerm);
        unordered_map<YAP_Term, LogVar>::iterator it = lvMap.find (ti);
        if (it != lvMap.end()) {
          logVars.push_back (it->second);
        } else {
         unsigned newLv = lvMap.size();
         lvMap[ti] = newLv;
         logVars.push_back (newLv);
        }
      }
      formulas.push_back (ProbFormula (functor, logVars, ranges[count]));
    }
    count ++;
    pvList = YAP_TailOfTerm (pvList);
  }

  // read the parameters
  const Params& params = readParameters (YAP_ArgOfTerm (4, pfTerm)); 

  // read the constraint
  Tuples tuples;
  if (lvMap.size() >= 1) {
    YAP_Term tupleList = YAP_ArgOfTerm (5, pfTerm);
    while (tupleList != YAP_TermNil()) {
      YAP_Term term = YAP_HeadOfTerm (tupleList);
      assert (YAP_IsApplTerm (term));
      YAP_Functor yapFunctor = YAP_FunctorOfTerm (term);
      unsigned arity = (unsigned) YAP_ArityOfFunctor (yapFunctor);
      assert (lvMap.size() == arity);
      Tuple tuple (arity);
      for (unsigned i = 1; i <= arity; i++) {
        YAP_Term ti = YAP_ArgOfTerm (i, term);
        if (YAP_IsAtomTerm (ti) == false) {
          cerr << "error: constraint has free variables" << endl;
          abort();
        }
        string name ((char*) YAP_AtomName (YAP_AtomOfTerm (ti)));
        tuple[i - 1] = LiftedUtils::getSymbol (name);
      }
      tuples.push_back (tuple);
      tupleList = YAP_TailOfTerm (tupleList);
    }
  }
  return new Parfactor (formulas, params, tuples, distId);
}
コード例 #8
0
ファイル: ProgressiveTopk.cpp プロジェクト: andyhehk/why-not
void PreComputeTA(char * filename, vector<vector<Cell> >& storebyrow, map<int, vector<float> >& index)
{
	Tuples allTuples;
	
	ReadData(filename, allTuples);

    int dimension;
    cout<<"Input Dimension:"<<endl;
    scanf("%d", &dimension);

	vector<list<Cell> >  sortedTuples(dimension);

    int position[5] = {0,1,2, 3, 4};

	for(Tuples::iterator iter = allTuples.begin(); iter!=allTuples.end(); iter++)
	{
		Tuple tuple = *iter;
		vector<float> needed_attr;
		
		for(int i=0; i<dimension; i++)
		{
			Cell temp;
			temp.ID = tuple.ID;
			try{
				temp.data = tuple.data.at(position[i]);
				needed_attr.push_back(temp.data);
				sortedTuples.at(i).push_back(temp);
			}
			catch(out_of_range outOfRange)
			{
				cout << "\n\nException1: "<<outOfRange.what()<<endl;
				cout<< tuple.data.size()<<","<<tuple.ID;
				return;
			}
		}

		index.insert(pair<int, vector<float> >(tuple.ID, needed_attr));
	}


	for(vector<list<Cell> >::iterator iter = sortedTuples.begin(); iter!=sortedTuples.end(); iter++)
	{
		(*iter).sort(compfn);

		list<Cell>  temp = *iter;

		if(storebyrow.empty())
		{
			for(list<Cell>::iterator iter1 = temp.begin(); iter1!=temp.end();iter1++)
			{
				vector<Cell> tempvector;
				Cell tempCell;

				tempCell.ID = iter1->ID;
				tempCell.data = iter1->data;

				tempvector.push_back(tempCell);

				storebyrow.push_back(tempvector);	
			}
		}

		else
		{
			unsigned int i = 0;
			for(list<Cell>::iterator iter1 = temp.begin(); iter1!=temp.end();iter1++, i++)
			{
				Cell tempCell;

				tempCell.ID = iter1->ID;
				tempCell.data = iter1->data;

				storebyrow[i].push_back(tempCell);
			}

			assert(i == temp.size());
		}
	}	


}