Esempio n. 1
0
int main()
{
    std::cout << std::boolalpha;
    constexpr unsigned sizes[]{4, 5, 3, 8, 6};

// Construction
    std::cout << "Construction : " << std::endl;
    std::array<char, sizes[0]> arr0{}, arr0b{{'f', 'r', 's', 'r'}}; // default
    std::array<char, sizes[1]> arr1 = {'e', 'q', 'g', 't', 'e'}, arr1b({0 + 'a', 4 + 'a', 5 + 'a', 2 + 'a', 3 + 'a'}); // braced list
    std::array<char, sizes[2]> arr2({'d', 's', 'a'}), arr2b = {7, 7, 'u'};

// Print elements
    print(arr0, "arr0");
    print(arr0b, "arr0b");
    print(arr1, "arr1");
    print(arr1b, "arr1b");
    print(arr2, "arr2");
    print(arr2b, "arr2b");

// Type aliases
    std::array<char, sizes[0]>::iterator it0(arr0.begin()); // iterator
    std::array<char, sizes[1]>::const_iterator cit1(arr1.begin()); // const_iterator
    std::array<char, sizes[0]>::reverse_iterator rit0(--arr0.rbegin()); // iterator
    std::array<char, sizes[1]>::const_reverse_iterator crit1(--arr1.crbegin()); // const_reverse_iterator
std::array<char, sizes[1]>::size_type sz1 = arr1.size(); // size_type
    std::array<char, sizes[2]>::difference_type diff2 = arr2.cend() - arr2.cbegin(); // difference_type
    std::array<char, sizes[2]>::value_type val2 = arr2[0]; // value_type
    std::array<char, sizes[2]>::reference ref2 = arr2[1]; // reference
    std::array<char, sizes[2]>::const_reference cref2 =arr2[3]; // const_reference

// Print iterators
    std::cout << "it0 : " << *it0 << std::endl;
    std::cout << "rit0 : " << *rit0 << std::endl;
    std::cout << "cit1 : " << *cit1 << std::endl;
    std::cout << "crit1 : " << *crit1 << std::endl;

    std::cout << "val2 : " << val2 << std::endl;
    std::cout << "ref2 : " << ref2 << std::endl;
    std::cout << "cref2 : " << cref2 << std::endl;

// Size operations
    std::cout << "arr1.size : " << sz1 << std::endl;
    std::cout << "arr2 size : " << diff2 << std::endl; // number of elements in container
    std::cout << "arr0.max_size : " << arr0.max_size() << std::endl;// max number of elements container can hold
    std::cout << "arr1.max_size : " << arr1.max_size() << std::endl; // true if container empty, false otherwise
    std::cout << "arr2.max_size : " << arr2.max_size() << std::endl;

// Swap
    std::cout << "Assignment and swap : " << std::endl;
    arr0 = arr0b; // copy assignment of object
    arr1b = {'a', 'b', 'c', 'd'}; // copy assignment of braced list
    arr2.swap(arr2b); // member style swap
    swap(arr1, arr1b); // function style swap

// Print elements
    print(arr0, "arr0");
    print(arr0b, "arr0b");
    print(arr1, "arr1");
    print(arr1b, "arr1b");
    print(arr2, "arr2");
    print(arr2b, "arr2b");

// Relational operations
    std::cout << "Relational operations : " << std::endl;
    std::cout << "arr0 == arr0b : " << (arr0 == arr0b) << std::endl; // ==
    std::cout << "arr1 != arr1b : " << (arr1 != arr1b) << std::endl; // !=
    std::cout << "arr2 < arr2b : " << (arr2 < arr2b) << std::endl; // <
    std::cout << "arr2 <= arr2b : " << (arr2 <= arr2b) << std::endl; // <=
    std::cout << "arr1 > arr1b : " << (arr1 > arr1b) << std::endl; // >
    std::cout << "arr0 >= arr0b : " << (arr0 >= arr0b) << std::endl; // >=

    return 0;
}
Esempio n. 2
0
int main(int argc, char *argv[])
{

	if(argc<3)
	{
	std::cout<<"usage: "<<"./test [RIF] [ANHO]"<<std::endl;
	return 0;
	}

	char* rif,*anho;
	rif=argv[1];
	anho=argv[2];

	DynDlist<UnidadEconomica> nodoraiz, nodofiltrado;

	std::ofstream file;

	Chain cadena;

	FetchRoot root("file.txt");
	std::locale loc;
   	rif[0]=std::toupper(rif[0],loc);
	std::string val;
//	file.open("out.json");
	file.open("media/tmp/out.json");


	if(rif[0]=='J'||rif[0]=='G')
	nodoraiz=root.searchByRif(rif,anho);
	else
	nodoraiz=root.searchByCode(rif,anho);


	file<<"{\t \"Raiz\":\t[";


	//ELIMINAR NODOS QUE NO TENGAN DATOS PARA MODELAR EN CADENA
	size_t i;
	for(DynDlist<UnidadEconomica>::Iterator it(nodoraiz);it.has_curr();it.next())
		{i=0;
			if(!it.get_curr().productos.is_empty())
			{
			  for(DynDlist<Productos>::Iterator itpr(it.get_curr().productos);itpr.has_curr();itpr.next())
				if(itpr.get_curr().insumos.is_empty())
				{
					swap(itpr.get_curr(),it.get_curr().productos[i]);
					i++;
				}

				for(int n=0;n<i;n++)
				it.get_curr().productos.pop();

			if(!it.get_curr().productos.is_empty())
			nodofiltrado.append(it.get_curr());


			}
		}
		


	//PARSER MANUAL A FORMATO JSON

	for(DynDlist<UnidadEconomica>::Iterator it(nodofiltrado);it.has_curr();)
	{

			file<<"{ \"roleName\":\""<<it.get_curr().nombre+" "+it.get_curr().rif<<"\",\"roleId\":\""<<it.get_curr().rif<<"\",\"children\":["<<std::endl;

			for (DynDlist<Productos>::Iterator it1(it.get_curr().productos);it1.has_curr();it1.next())
			{

				file<<"{\"roleName\":\""<<it1.get_curr().nombre+" "+it1.get_curr().cod_aran<<"\",\"roleId\":\""<<it1.get_curr().id<<"\",\"children\":["<<std::endl;
				for(DynDlist<Insumos>::Iterator it0(it1.get_curr().insumos);it0.has_curr();it0.next())
				{

				file<<"{\"roleName\":\""<<std::get<0>(it0.get_curr()).nombre+" "+std::get<0>(it0.get_curr()).cod_aran<<"\",\"roleId\":\""<<std::get<0>(it0.get_curr()).cantidad<<"\",\"children\":["<<std::endl;

					for(DynDlist<Proveedor>::Iterator it2(std::get<1>(it0.get_curr()));it2.has_curr();it2.next())
					{
					file<<"{\"roleName\":\""<<it2.get_curr().nombre+" "+it2.get_curr().paisProcedencia<<"\",\"roleId\":\""<<it2.get_curr().rif<<"\",\"children\":[]}";

					if(it2.get_pos()!=std::get<1>(it0.get_curr()).size()-1 && std::get<1>(it0.get_curr()).size()!=1)
					file<<","<<std::endl;

					}
					if(it0.get_pos()!=it1.get_curr().insumos.size()-1)
					file<<"]},"<<std::endl;
					else
					file<<"]}"<<std::endl;

				}

				if(it1.get_pos()!=it.get_curr().productos.size()-1)
				file<<"]},"<<std::endl;
				else
				file<<"]}"<<std::endl;

			}

			if(it.get_pos()!=nodofiltrado.size()-1)
			file<<"]},"<<std::endl;
			else
			file<<"]}"<<std::endl;

			it.next();



	}
	
	file<<"]}";
	file.close();
	std::cout<<std::endl<<"DONE!!"<<std::endl;
	return 0;


}
Esempio n. 3
0
MGraph<ClusterAlg*, unsigned>* ClusterAlg::constructGraph(ClusterAlg* other, unsigned up)
{
  std::list<ClusterAlg*> list_graph_nodes;

  ClusterAlg *p0 = this, *p1 = other;
  // search for roots of subtrees in the cluster tree
  findRoots (p0, p1);

  if (p0 == NULL || p1 == NULL) return NULL;
  if (p0->getDepth() < up || p1->getDepth() < up) return NULL;
  for (unsigned l=0; l<up; ++l) {
    p0 = (ClusterAlg*)p0->getParent();
    p1 = (ClusterAlg*)p1->getParent();
  }

  // fill list_graph_nodes with the appropriate graph nodes
  if (p0 == p1) p1->getNodes (depth, list_graph_nodes);
  else {
    p0->getNodes (depth, list_graph_nodes);
    p1->getNodes (depth, list_graph_nodes);
  }

  // create and fill vertex array for graph (adjacency matrix)
  unsigned row_size = list_graph_nodes.size(), idx = 0;
  ClusterAlg **graph_nodes = new ClusterAlg* [row_size];

  std::list<ClusterAlg*>::iterator node_it = list_graph_nodes.begin ();
  while (node_it != list_graph_nodes.end()) {
    graph_nodes[idx++] = *node_it;
    node_it++;
  }

  // count nnz-elements, fill liA, ljA and lA
  std::list<unsigned> liA, ljA, lA;
  liA.push_back (0);
  unsigned col = 0, col_cnt;
  std::list<ClusterAlg*>::iterator it0(list_graph_nodes.begin ()), it1;
  while (it0 != list_graph_nodes.end()) {
    it1 = list_graph_nodes.begin ();
    col_cnt = 0;
    while (it1 != list_graph_nodes.end()) {
      if (it0 != it1) {
        unsigned nbr_size ((*it0)->hasNeighbour(*it1));
#ifdef VIRTUAL_DEPTH_WEIGHT
        if (nbr_size > 0) {
          ljA.push_back (col_cnt);
          col++;
          // determine weights
          if ((*it0)->isSeparator() && (*it1)->isSeparator()) {
            unsigned diff0 ((*it0)->getDepth()-(*it0)->getVirtualDepth()+1);
            unsigned diff1 ((*it1)->getDepth()-(*it1)->getVirtualDepth()+1);
            if (diff0 < diff1) lA.push_back (diff0);
            else lA.push_back(diff1);
          } else {
            if ((*it0)->isSeparator() && !(*it1)->isSeparator())
              lA.push_back ((*it0)->getDepth()-(*it0)->getVirtualDepth()+1);
            else lA.push_back ((*it1)->getDepth()-(*it1)->getVirtualDepth()+1);
          }
        }
#endif

#ifdef NEIGHBOUR_SIZE_WEIGHT
        if (nbr_size) {
          ljA.push_back (col_cnt);
          col++;
          // determine weights
          if ((*it0)->isSeparator() && (*it1)->isSeparator()) {
            unsigned mnbr_size (nbr_size > (*it1)->hasNeighbour(*it0) ? nbr_size : (*it1)->hasNeighbour(*it0));
            unsigned min_diam ((*it0)->getDiam() < (*it1)->getDiam() ? (*it0)->getDiam() : (*it1)->getDiam());
            lA.push_back (ceil((double)min_diam / mnbr_size));
          } else {
            if ((*it0)->isSeparator() && !(*it1)->isSeparator()) {
              if (ceil((double)(*it0)->getDiam()/nbr_size) == 1)
                lA.push_back (ceil(sqrt((double)(*it0)->getDiam())));
              else lA.push_back (ceil((double)(*it0)->getDiam()/nbr_size));
            } else {
              if (ceil((double)(*it1)->getDiam()/nbr_size) == 1)
                lA.push_back (ceil(sqrt((double)(*it1)->getDiam())));
              else lA.push_back (ceil((double)(*it1)->getDiam()/nbr_size));
            }
          }
        }
#endif

#ifdef UNWEIGHTED
        if (nbr_size > 0) {
          ljA.push_back (col_cnt);
          lA.push_back (1);
          col++;
        }
#endif
      }
      it1++;
      col_cnt++;
    }
    liA.push_back (col);
    it0++;
  }

  // create AdjMat in CRS-format: iA, jA, A
  unsigned *iA = new unsigned[row_size+1];
  unsigned col_ptr_size = ljA.size();
  unsigned *jA = new unsigned[col_ptr_size];
  unsigned  *A = new unsigned[col_ptr_size];

  // fill iA
  std::list<unsigned>::const_iterator it2 = liA.begin ();
  idx = 0;
  while (it2 != liA.end()) {
    iA[idx++] = *it2;
    it2++;
  }
  iA[row_size] = col_ptr_size;

  // fill jA and A
  it2 = ljA.begin ();
  std::list<unsigned>::const_iterator it3 (lA.begin());
  idx = 0;
  while (it2 != ljA.end()) {
    jA[idx] = *it2;
    A[idx] = *it3;
    it2++;
    it3++;
    idx++;
  }

  AdjMat *tmp_adj(new AdjMat (row_size, iA, jA, A));

  MGraph <ClusterAlg*, unsigned> *graph
  (new MGraph<ClusterAlg*, unsigned> (graph_nodes, tmp_adj));

  delete [] graph_nodes;
  return graph;
}