Esempio n. 1
0
typename std::set<Connection*> WeightedPoll::get_objects(){
    typename std::set<Connection*> items;
    for(typename std::map<Connection*,double>::iterator it = counter.begin(); it != counter.end(); ++it) {
        items.insert(it->first);
    }
    return items;
}
Esempio n. 2
0
	template<typename T> std::set<T> UnionSets(const std::set<T>& s1, const std::set<T>& s2) {
		typename std::set<T> r;
		typename std::set<T>::const_iterator sit;

		for (sit = s1.begin(); sit != s1.end(); sit++) { r.insert(*sit); }
		for (sit = s2.begin(); sit != s2.end(); sit++) { r.insert(*sit); }

		return r;
	}
  void setup_stiffness_matrix(PROBLEM& P,
			      const std::set<typename PROBLEM::Index>& Lambda1,
			      const std::set<typename PROBLEM::Index>& Lambda2,
			      SparseMatrix<double>& A_Lambda,
			      bool preconditioned)
  {
      cout << "setup_stiffness_matrix()" << endl;
    A_Lambda.resize(Lambda1.size(), Lambda2.size());
    
    typedef typename SparseMatrix<double>::size_type size_type;


    size_type row = 0;
    typedef typename PROBLEM::Index Index;
    typedef std::list<Index> IntersectingList;
      
    for (typename std::set<Index>::const_iterator it1(Lambda1.begin()), itend(Lambda1.end());
	 it1 != itend; ++it1, ++row)
      {

	// determine list of thise indices which intersect with *it1
	IntersectingList Nu;
	intersecting_wavelets(P.basis(), *it1.p(), *it1.p(), Lambda2, Nu);

	const double d1 = preconditioned ? P.D(*it1) : 1.0;
	std::list<size_type> indices;
	std::list<double> entries;

	size_type column = 0;

// 	for (typename std::set<Index>::const_iterator it2(Lambda2.begin()), itend2(Lambda2.end());
// 	     it2 != itend2; ++it2, ++column)
	for (typename std::list<Index>::const_iterator it2(Nu.begin()), itend2(Nu.end());
	     it2 != itend2; ++it2, ++column)

	  {
	    //if (intersect_singular_support(P.basis(), *it1, *it2))
	    //double entry = P.a(*it2, *it1);
	    double entry = P.a(*it1, *it2);
	      
	    //const double entry = 0;
#if _WAVELETTL_GALERKINUTILS_VERBOSITY >= 2
 	    if (fabs(entry) > 1e-15) {
 	      cout << " column: " << *it2 <<  ", value " << entry << endl;
 	    }
#endif
	    if (fabs(entry) > 1e-15) {
		indices.push_back(column);
		entries.push_back(entry / (preconditioned ? d1 * P.D(*it2) : 1.0));
	    }
	    // 	    }
	  }
	A_Lambda.set_row(row, indices, entries);
      }
        cout << "done" << endl;
  }
Esempio n. 4
0
	template<typename T> std::set<T> IntersectSets(const std::set<T>& s1, const std::set<T>& s2) {
		typename std::set<T> r;
		typename std::set<T>::const_iterator sit;

		for (sit = s1.begin(); sit != s1.end(); sit++) {
			if (s2.find(*sit) != s2.end()) {
				r.insert(*sit);
			}
		}

		return r;
	}
Esempio n. 5
0
template <typename Key, typename Compare, typename Alloc> std::set<Key, Compare, Alloc> set_difference(const std::set<Key, Compare, Alloc>& set1, const std::set<Key, Compare, Alloc>& set2)
{
	typename std::set<Key, Compare, Alloc> result;
	Compare comp;
	std::set_difference(set1.begin(), set1.end(), set2.begin(), set2.end(), std::inserter(result, result.end()), comp);
	return result;
}
Esempio n. 6
0
    const Matrix* BooleanInvolutiveBasis<MonomType>::ToMatrix() const
    {
        MatrixConstructor matrixConstructor(PRing->make_FreeModule(1), 0);
        const Monoid* monoid = PRing->getMonoid();
        const ring_elem coefficientUnit = PRing->getCoefficients()->one();
        monomial tmpRingMonomial = monoid->make_one();
        
        for (typename std::list<Polynom<MonomType>*>::const_iterator currentPolynom = GBasis.begin(); 
             currentPolynom != GBasis.end(); 
             ++currentPolynom)
        {
            if (!*currentPolynom)
            {
                continue;
            }
            
            ring_elem currentRingPolynomial;

            for (const MonomType* currentMonom = &(**currentPolynom).Lm(); 
                 currentMonom; 
                 currentMonom = currentMonom->Next)
            {
                exponents currentExponent = newarray_atomic_clear(int, MonomType::GetDimIndepend());
                typename std::set<typename MonomType::Integer> variablesSet = currentMonom->GetVariablesSet();
                
                for (typename std::set<typename MonomType::Integer>::const_iterator currentVariable = variablesSet.begin();
                     currentVariable != variablesSet.end();
                     ++currentVariable)
                {
                    currentExponent[*currentVariable] = 1;
                }
                
                monoid->from_expvector(currentExponent, tmpRingMonomial);
                deletearray(currentExponent);

                ring_elem tmpRingPolynomial = PRing->make_flat_term(coefficientUnit, tmpRingMonomial);
                PRing->add_to(currentRingPolynomial, tmpRingPolynomial);
            }
            
            matrixConstructor.append(PRing->make_vec(0, currentRingPolynomial));
        }
        
        return matrixConstructor.to_matrix();
    }
Esempio n. 7
0
void Generator<Annotation, Runtime, Driver>::generate(
  const LoopTrees<Annotation> & loop_trees,
  std::set<std::list<Kernel<Annotation, Runtime> *> > & kernel_lists,
  LoopMapper<Annotation, Runtime> & loop_mapper,
  LoopTiler<Annotation, Runtime> & loop_tiler,
  DataFlow<Annotation, Runtime> & data_flow
) {
  typedef typename LoopTrees<Annotation>::loop_t loop_t;
  typedef typename LoopTiler<Annotation, Runtime>::loop_tiling_t loop_tiling_t;
  typedef Kernel<Annotation, Runtime> Kernel;

  typename std::set<std::list<Kernel *> >::const_iterator it_kernel_list;
  typename std::list<Kernel *>::const_iterator it_kernel;

  typename DataFlow<Annotation, Runtime>::context_t df_ctx;

  // 0 - init data flow

  data_flow.createContextFromLoopTree(loop_trees, df_ctx);
  data_flow.markSplittedData(df_ctx);

  // 1 - Loop Selection : Generate multiple list of kernel that implement the given LoopTree

  loop_mapper.createKernels(loop_trees, kernel_lists);

  // 2 - Data Flow : performs data-flow analysis for each list of kernel

  for (it_kernel_list = kernel_lists.begin(); it_kernel_list != kernel_lists.end(); it_kernel_list++)
    data_flow.generateFlowSets(*it_kernel_list, df_ctx);

  // 3 - Arguments : determines the list of arguments needed by each kernel

  for (it_kernel_list = kernel_lists.begin(); it_kernel_list != kernel_lists.end(); it_kernel_list++)
    for (it_kernel = it_kernel_list->begin(); it_kernel != it_kernel_list->end(); it_kernel++)
      buildArgumentLists(loop_trees, *it_kernel);

  for (it_kernel_list = kernel_lists.begin(); it_kernel_list != kernel_lists.end(); it_kernel_list++)
    for (it_kernel = it_kernel_list->begin(); it_kernel != it_kernel_list->end(); it_kernel++) {

      // 4 - Iterations Mapping : determines the "shape" of every loop of each kernel.
      //     The "shape" of a loop is how this loop is adapted to the execution model.

      std::map<loop_t *, std::vector<loop_tiling_t *> > tiling_map;

      loop_tiler.determineTiles(*it_kernel, tiling_map);

      std::set<std::map<loop_t *, loop_tiling_t *> > loop_tiling_set;
      buildAllTileConfigs<Annotation, Runtime>(
        std::map<loop_t *, loop_tiling_t *>(),
        tiling_map.begin(),
        tiling_map.end(),
        loop_tiling_set
      );

      // 5 - Code Generation

      size_t cnt = 0;
      typename std::set<std::map<loop_t *, loop_tiling_t *> >::iterator it_loop_tiling_map;
      for (it_loop_tiling_map = loop_tiling_set.begin(); it_loop_tiling_map != loop_tiling_set.end(); it_loop_tiling_map++) {
        typename ::MFB::KLT<Kernel>::object_desc_t kernel_desc(cnt++, *it_kernel, p_file_id);

        kernel_desc.tiling.insert(it_loop_tiling_map->begin(), it_loop_tiling_map->end());

        typename Kernel::kernel_desc_t * kernel = p_driver.template build<Kernel>(kernel_desc);

        (*it_kernel)->addKernel(kernel);
      }
      typename std::map<loop_t *, std::vector<loop_tiling_t *> >::const_iterator it_tiling_vect;
      typename std::vector<loop_tiling_t *>::const_iterator it_tiling;
      for (it_tiling_vect = tiling_map.begin(); it_tiling_vect != tiling_map.end(); it_tiling_vect++)
        for (it_tiling = it_tiling_vect->second.begin(); it_tiling != it_tiling_vect->second.end(); it_tiling++)
          delete *it_tiling;
      
    }
}
Esempio n. 8
0
std::list<STATE> AStar(const STATE& start, const STATE& target,
                       boost::function<void (const STATE&, const STATE&,
                                             const STATE&,
                                             std::vector<STATE>&,
                                             std::vector<STATE>&)>
                       generate_next_states)
{
    //std::cout<<"start A* ------------------"<<std::endl;
    std::set<STATE> open;
    std::set<STATE> closed;

    STATE current = start;
    while ( current.moreCost() > 0.0000001f ){
        //std::cout<<"state: "<<current.p()<<std::endl;
        typename std::set<STATE>::iterator iter = closed.begin();
        for(; closed.end() != iter; ++iter){
            if ( iter->sameAs(current) ) break;
        }
        if ( closed.end() == iter ){
            // insert to closed
            closed.insert(current);
        }

        iter = open.begin();
        for(; open.end() != iter; ++iter){
            if (iter->sameAs(current)){
                open.erase(iter);
                break;
            }
        }
            
        std::vector<STATE> nextStates, unReach;
        generate_next_states(current, target, target, nextStates, unReach);
        //std::cout<<"next size: "<<nextStates.size()<<std::endl;
        for( typename std::vector<STATE>::iterator iter=nextStates.begin();
             nextStates.end()!=iter; ++iter){
                
            typename std::set<STATE>::iterator citer = closed.begin();
            for(; citer != closed.end(); ++citer){
                if ( citer->sameAs(*iter) ) break;
            }
                
            if ( closed.end() != citer ){
                //std::cout<<"the state "<<iter->p()
                //<<"have been closed"<<std::endl;
                continue; // the state have be closed
            }

            iter->setPrevious(current);
                
            typename std::set<STATE>::iterator oiter = open.begin();
            for(; oiter != open.end(); ++oiter){
                if ( oiter->sameAs(*iter) ) break;
            }
                
            if ( open.end() == oiter ){
                //std::cout<<"insert "<<iter->p()
                //<<" ("<<iter->cost()<<")"<<std::endl;
                open.insert(*iter); // first reach this state
            }
            else{
                if ( oiter->cost() > iter->cost() ){
                    //std::cout<<"refresh "<<iter->p()
                    //<<" "<<oiter->cost()<<" -> "
                        //<<iter->cost()<<std::endl;
                    // find a better path to reach this state
                    open.erase(oiter);
                    open.insert(*iter);
                }
            }
        }

        if ( open.empty() ){
            //std::cout<<"no path! open empty"<<std::endl;
            break; // no path!
        }

        // start from the best state at currently
        current = *open.begin();
    }

    std::list<STATE> path;
    while ( !start.sameAs(current) )
    {
        path.push_front(current);
        STATE previous = current.previous();
        typename std::set<STATE>::const_iterator p = closed.begin();
        for(; p!=closed.end(); ++p ){
            if ( previous.sameAs(*p) ) break;
        }
        if ( closed.end() == p ){
            //std::cout<<"no path! closed empty"<<std::endl;
            // no path: closed empty!
            break;
        }
        current = *p;
    }

    //std::cout<<"end A* ----------------"<<std::endl;
    return path;
}
Esempio n. 9
0
            PathType getPath(const GraphAdapterType& graphAdapter, const NodeAdapterType& start, const std::function<bool(const NodeAdapterType&)>& endCondition) const {
                PathType resultPath;

                struct NodePositionComparator {
                    bool operator() (const NodeAdapterType& lhs, const NodeAdapterType& rhs) {
                        return lhs.position < rhs.position;
                    }
                };

                std::set<NodeAdapterType> open = { start };
                std::set<NodeAdapterType, NodePositionComparator> closed;
                std::map<NodeAdapterType, NodeAdapterType, NodePositionComparator> came_from;
                typename std::set<NodeAdapterType>::iterator current;

                while(open.empty() == false) {
                    current = open.begin();

                    if(endCondition(*current) == true) {
                        // Goal found, recreating path from 'goal' node to 'start' node
                        resultPath.push_front(current->position);
                        auto pathCurrent = came_from.find(*current);
                        if(pathCurrent != came_from.end()) {
                            while(pathCurrent->second.position != start.position) {
                                resultPath.push_front(pathCurrent->second.position);
                                pathCurrent = came_from.find(pathCurrent->second);
                            }
                        }

                        return resultPath;
                    }

                    closed.insert(*current);

                    std::vector<NodeAdapterType> neighbours = graphAdapter.getNeighboursOf(*current);
                    for(NodeAdapterType& neighbour : neighbours) {
                        if(graphAdapter.isAvailable(neighbour.position)) {
                            typename std::set<NodeAdapterType>::iterator cIter, oIter;

                            cIter = closed.find(neighbour);
                            if(cIter != closed.end()) {
                                continue;
                            }

                            neighbour.g(current->g() + 1);
                            neighbour.h(graphAdapter.getHeuristicCostLeft(neighbour, neighbour));

                            oIter = open.find(neighbour);
                            if(oIter == open.end() || neighbour.g() < oIter->g()) {
                                if(oIter != open.end()) {
                                    open.erase(oIter);
                                }

                                auto cameFromIter = came_from.find(neighbour);
                                if(cameFromIter != came_from.end()) {
                                    if(cameFromIter->second.g() > neighbour.g()) {
                                        came_from.erase(cameFromIter);
                                    }
                                }
                                came_from.emplace(std::pair<NodeAdapterType, NodeAdapterType>(neighbour, *current));

                                open.insert(neighbour);
                            }
                        }
                    }

                    open.erase(current);
                }

                // If algorithm comes here, no path was found, and return value of this method will be empty vector

                return resultPath;
            }
Esempio n. 10
0
int test_lrs(){
        typedef NT_                                             NT;
        typedef std::vector<NT>                                 Point;
        typedef std::vector<Point>                              Points;
        typedef std::vector<NT>                                 Normal;
        typedef std::set<std::vector<NT> >                      Polytope;

        // construct the input, the points and the vector containing them
        Point p(2),q(2),r(2),s(2);
        p[0]=NT(0);p[1]=NT(0);
        q[0]=NT(3);q[1]=NT(3);
        r[0]=NT(0);r[1]=NT(3);
        s[0]=NT(1);s[1]=NT(2);
        Points input(4);
        input[0]=p;input[1]=q;input[2]=r;input[3]=s;
        // create a LRS_CH object
        LRS_CH<NT> ch_object(input);
        // output the H-representation
        Polytope output=ch_object.get_h_rep();
        // check that the output is three hyperplanes
        if(output.size()!=3)
                return -1;
        typename Polytope::const_iterator hi=output.begin();
        // check that the first element is [-1,1,0]
        if(hi->size()!=3)
                return -2;
        if((*hi)[0]!=-1||(*hi)[1]!=1||(*hi)[2]!=0)
                return -3;
        // check that the second element is [0,-1,3]
        ++hi;
        if(hi->size()!=3)
                return -4;
        if((*hi)[0]!=0||(*hi)[1]!=-1||(*hi)[2]!=3)
                return -5;
        // check that the third element is [1,0,0]
        ++hi;
        if(hi->size()!=3)
                return -6;
        if((*hi)[0]!=1||(*hi)[1]!=0||(*hi)[2]!=0)
                return -7;
        // now, check the normals
        std::set<Normal> normals=ch_object.get_normals();
        // check that there are three normals
        if(normals.size()!=3)
                return -8;
        typename std::set<Normal>::const_iterator ni=normals.begin();
        // check that the first element is [-1,0]
        if(ni->size()!=2)
                return -9;
        if((*ni)[0]!=-1||(*ni)[1]!=0)
                return -10;
        // check that the second element is [0,1]
        ++ni;
        if(ni->size()!=2)
                return -11;
        if((*ni)[0]!=0||(*ni)[1]!=1)
                return -12;
        // check that the third element is [1,-1]
        ++ni;
        if(ni->size()!=2)
                return -13;
        if((*ni)[0]!=1||(*ni)[1]!=-1)
                return -14;
        return 0;
}