Пример #1
0
void ADT::moveNodes (Node *&leaf, Node *&otherLeaf)
{
    if (otherLeaf != NULL)
    {
        leaf = otherLeaf;
        
        if (otherLeaf->left != NULL)
        {
            moveNodes (leaf->left, otherLeaf->left);
        }
        if (otherLeaf->right != NULL)
        {
            moveNodes (leaf->right, otherLeaf->right);
        }
        
        //leaf = move(otherLeaf);
        otherLeaf = NULL;
    }
}
int main()
{
    constexpr unsigned N = 5;
    list listx = nullptr;

    //Pointers used for moving nodes
    list nodex = nullptr;
    list nodet = nullptr;
    createCircularList(listx,N);
    printList(listx);
    //Points used for sorting nodes
    nodex = nodet = listx;
    nodex = nodex->next->next;
    nodet = nodet->next->next->next->next;
    //if list elemets are 1 2 3 4 5, then
    //after calling the function list becomes 1 4 2 3 5, this  of course
    //is considering current positions for both nodex and nodet
    moveNodes(nodex, nodet);
    printList(listx);
    deleteList(listx);
    return 0;
}
Пример #3
0
void FlatListModel::move(int from, int to, int n)
{
    qdeclarativelistmodel_move<QList<QHash<int, QVariant> > >(from, to, n, &m_values);
    moveNodes(from, to, n);
}
Пример #4
0
MappingInfo DistanceMapper::reduce_dimensions(std::vector<std::vector<float> >& dimFactorVector)
{
  
  MappingInfo dummyInfo;
  if(!nodes || !node_distances || !forceVectors || !mappedNodes)
    return(dummyInfo);
  // we have to verify that the dimFactorVector is reasonable
  // Each sub vector should be of dimensionality length and
  // each value should be between 1 and 0, though actually
  // one might be able to create interesting effects by using
  // different values.
  if(dimFactorVector.size() == 0){
    Rprintf("Error: reduce_dimensions no iterations specified\n");
    return(dummyInfo);
  }
  unsigned int df_size = dimFactorVector[0].size();
  for(unsigned int i=0; i < dimFactorVector.size(); ++i){
    if(dimFactorVector[i].size() != df_size){
      Rprintf("Incorrect DimFactorVector specified iteration %d has %d dimensions\n",
	      i, dimFactorVector[i].size());
      Rprintf("Using default dimension strategy\n");
      return( reduce_dimensions(dimFactorVector.size(), 2) ); // potential infinite loop
    }
  }

  unsigned int iter_no = dimFactorVector.size();
  std::vector<stressInfo> stress_data(iter_no);

  // make sure that the mappedNodes are set to the original ones.
  // This should be optional, as we may want to keep the nodes for a longer time.
  memcpy((void*)mappedNodes, (void*)nodes, sizeof(float) * node_no * dimension_no);
  
  Rprintf("Squeezing\n");
  // Let's print out 80 colums to indicate progress
  unsigned int columns = 80;
  unsigned int div = (iter_no / columns);
  div = (div == 0) ? 1 : div;
  for(unsigned int i=0; i < iter_no; ++i){
    if(!(i % div)) Rprintf("-");
  }
  Rprintf("|\n");
  
  for(unsigned int i=0; i < iter_no; ++i){
    // progress bar
    if(!(i % div))
      Rprintf("=");
    dimFactors = dimFactorVector[i];  // this is a hack to allow setting of dimFactors
    float stress = adjustForces();
    stress_data[i].setStress(dimFactors, stress);
    
    moveNodes();
  }
  Rprintf("\n");
  // Reduce stress while it is decreasing, or we reach a max iteration no.
  float last_stress = stress_data.back().stress;
  bool remove_residual_stress = _remove_residual_stress;
  while(remove_residual_stress && stress_data.size() < (3 * iter_no)){
    Rprintf(".");
    float stress = adjustForces();
    moveNodes();
    //    Rprintf("%f\t%f\n", last_stress, stress);
    stress_data.push_back( stressInfo(dimFactors, stress) );
    remove_residual_stress = (stress < last_stress);
    last_stress = stress;
  }
  Rprintf("\n");

  // prepare the mapping info in a reasonable manner
  std::map<std::string, float> time_data;
  time_data["Undefined"] = 0;

  // make a copy of the mappedNodes
  float* node_copy = new float[ node_no * dimension_no ];
  memcpy((void*)node_copy, (void*)mappedNodes, sizeof(float) * node_no * dimension_no);

  return( MappingInfo(node_no, dimension_no, node_copy, stress_data, time_data, node_stress) ); 
}