int Iter::operator* () const { return _p_vec->get(_pos); } // Fill in the method definition.
bool MSProductParameters::getSequenceElements ( ParameterList* params, const string& num, string& sequence, string& nTermName, string& cTermName, string& neutralLossName )
{
	sequence = params->getStrippedStringValue ( "sequence" + num, "" );
	if ( sequence.empty () ) return false;
	nTermName = params->getStringValue ( "nterm" + num, "" );
	cTermName = params->getStringValue ( "cterm" + num, "" );
	neutralLossName = params->getStringValue ( "nloss" + num, "" );
	if ( nTermName.empty () && cTermName.empty () && neutralLossName.empty () ) {
		static StringVector nTermNames = ConstMod::getNTermNames ();
		static StringVector cTermNames = ConstMod::getCTermNames ();
		static StringVector nLossNames = ConstMod::getNLossNames ();
		IntVector plusIdx;
		IntVector minusIdx;
		for ( StringSizeType i = 0 ; i < sequence.length () ; i++ ) {
			char p = sequence [i];
			if ( p == '+' )		plusIdx.push_back ( i );
			else if ( p == '-' )minusIdx.push_back ( i );
			else if ( p == '(' ) {
				int bracket = 0;
				for ( ; i < sequence.length () ; i++ ) {
					char a = sequence [i];
					if ( a == '(' ) bracket++;
					if ( a == ')' ) bracket--;
					if ( bracket == 0 ) break;
				}
			}
		}
		if ( !plusIdx.empty () ) {
			for ( int i = 0 ; i < nLossNames.size () ; i++ ) {
				string nL = nLossNames [i];
				if ( isSuffix ( sequence, "+" + nL ) ) {
					sequence = sequence.substr ( 0, sequence.length () - 1 - nL.length () );
					neutralLossName = nL;
					break;
				}
			}
			if ( neutralLossName.empty () ) {
				string possNLoss = sequence.substr ( plusIdx.back () + 1 );	// Add 1 to the last +
				if ( genStringIsFloat ( possNLoss ) ) {						// Check if number
					sequence = sequence.substr ( 0, plusIdx.back () );
					neutralLossName = possNLoss;
				}
			}
			while ( !minusIdx.empty () && minusIdx.back () >= sequence.length () ) minusIdx.pop_back ();
		}
		if ( !minusIdx.empty () ) {
			for ( int i = 0 ; i < cTermNames.size () ; i++ ) {
				string nC = cTermNames [i];
				if ( nC.empty () ) continue;
				if ( isSuffix ( sequence, "-" + nC ) ) {
					sequence = sequence.substr ( 0, sequence.length () - 1 - nC.length () );
					cTermName = nC;
					break;
				}
			}
			if ( cTermName.empty () ) {
				int idx = minusIdx.back ();
				if ( sequence [idx-1] != '-' ) idx += 1;
				string possCTerm = sequence.substr ( idx );	// Add 1 to the last -
				if ( genStringIsFloat ( possCTerm ) ) {							// Check if number
					sequence = sequence.substr ( 0, idx - 1 );
					cTermName = possCTerm;
				}
			}
			while ( minusIdx.back () >= sequence.length () ) minusIdx.pop_back ();
		}
		if ( !minusIdx.empty () ) {
			for ( int j = 0 ; j < nTermNames.size () ; j++ ) {
				string nN = nTermNames [j];
				if ( nN.empty () ) continue;
				if ( isPrefix ( sequence, nN + "-" ) ) {
					sequence = sequence.substr ( nN.length () + 1 );
					nTermName = nN;
					break;
				}
			}
			if ( nTermName.empty () ) {
				int idx = ( sequence [0] == '-' ) ? minusIdx [1] : minusIdx [0];
				string possNTerm = sequence.substr ( 0, idx );
				if ( genStringIsFloat ( possNTerm ) ) {							// Check if number
					sequence = sequence.substr ( idx + 1 );
					nTermName = possNTerm;
				}
			}
		}
		params->addOrReplaceName ( "sequence" + num, sequence );
		params->addOrReplaceName ( "nterm" + num, nTermName );
		params->addOrReplaceName ( "cterm" + num, cTermName );
		params->addOrReplaceName ( "nloss" + num, neutralLossName );
	}
	return true;
}
示例#3
0
TEST(IntegerVectorTest, ScalarConstructor) {
    IntVector* scalar = IntVector::createScalar(17);
    ASSERT_EQ(1, scalar->size());
    EXPECT_EQ(17, (*scalar)[0]);
}
示例#4
0
bool Split::containAny(IntVector &tax_id) {
	for (IntVector::iterator it = tax_id.begin(); it != tax_id.end(); it++)
		if (containTaxon(*it)) return true;
	return false;
}
示例#5
0
Path NewMIRAAlgorithm::compute(const Flow &flow)
{
    TRACE("NewMIRAAlgorithm::compute -->");

    Topology *topology = flow.getTopology();
    const int f_src = flow.getSource();
    const int f_dst = flow.getDestination();

    // if link (i,j) exists, its metric is initialized with 0 (it increases each
    // time a maxflow computation is performed) and it is added to the list that
    // feeds the maxflow function
    int numarcs = 0;
    int number_of_nodes = topology->getNumNodes();

    // data structure passed to maxflow function
    char** network = (char**) calloc(4, sizeof(char*));

    for (LinkListIterator iter = topology->getLinkIterator(); iter(); ++iter)
    {
        Link* link = *iter;
        if (link->getCapacity() > 0.0)
        {
            link->metric = 0.0;
            ++numarcs;
            network = (char**) realloc(network, (numarcs+4)*sizeof(char*));
            network[numarcs+2] = (char*) calloc(20, sizeof(char));
            sprintf(network[numarcs+2],"a %d %d %d",
                    link->getSource(), link->getDestination(),
                    (int) floor(link->getReservableCapacity()));
        } // end: if (link->
    } // end: for (LinkListIterator iter

    network[0] = (char*) calloc(20, sizeof(char));   // problem description
    network[1] = (char*) calloc(20, sizeof(char));   // source node
    network[2] = (char*) calloc(20, sizeof(char));   // destination node
    network[numarcs+3] = (char*) 0;       // NULL terminated array
    sprintf(network[0],"p max %d %d", number_of_nodes, numarcs);

#ifndef NO_TIMER
    Timer timer;
    timer.start();
#endif // NO_TIMER
    // Compute maxflow for each ingress-egress pair except (source,dest).
    // Each computation updates link weights

    //Timer timemaxflow;
    //timemaxflow.start();
    //int n = 0;

    const IntVector edge_nodes = topology->getEdgeNodes();

    for (IntVector::const_iterator s_iter = edge_nodes.begin();
            s_iter != edge_nodes.end(); ++s_iter)
    {
        for (IntVector::const_iterator d_iter = edge_nodes.begin();
                d_iter != edge_nodes.end(); ++d_iter)
        {
            if (*s_iter != *d_iter && !(f_src == *s_iter && f_dst == *d_iter))
            {

                //PRINTLN("s: " << *s_iter << "\td: " << *d_iter << "\tn: " << n);
                //n++;

                // complete network with current ingress-egress pair
                sprintf(network[1],"n %d s", *s_iter);
                sprintf(network[2],"n %d t", *d_iter);

                // needed by maxflow function
                node *ndp;
                arc *arp;
                long *cap;
                double mflow;
                long nmin;

                //compute maxflow
                //Timer t;
                //t.start();
                maxflow(network,&ndp,&arp,&cap,&mflow,&nmin);

                //PRINTLN("\tTimer: " << t.read());

                // update link weights
                for (node* in = ndp; in < (ndp + number_of_nodes); ++in)
                {
                    for (arc* a = in->first; a != 0; a = a->next)
                    {
                        long ni = N_NODE(in);
                        long na = N_ARC(a);
                        if ( cap[na] > 0 )
                        {
                            Link* link = topology->link(ni, N_NODE(a->head));
                            link->metric +=(cap[na] - a->r_cap) /
                                           (mflow*link->getReservableCapacity());
                        } // end: if ( cap[na] > 0 )
                    } // end: for ( arc*
                } // end: for (node*
                // free memory
                free(ndp);
                free(arp);
                free(cap);
            } // end: if ( (source
        } // end: for (int dest
    } // end: for (int source

    //PRINTLN("Timer: " << timemaxflow.read() << "\tn:" << n);

    // free memory
    for (int i=0; i<numarcs+3; ++i)
    {
        free(network[i]);
    }
    free(network);

    double f_cap = flow.getRequestedCapacity();
    // pruning of the links with insufficient bandwidth
    for (LinkListIterator iter = topology->getLinkIterator(); iter(); ++iter)
    {
        if ((*iter)->getReservableCapacity() < f_cap)
        {
            (*iter)->metric = -1.0;
        }
    }
    // invoking Dijkstra
    Path result(routing_alg->compute(flow));
#ifndef NO_TIMER
    const_cast<Flow&>(flow).setTime(timer.read());
#endif // NO_TIMER

    TRACE("NewMIRAAlgorithm::compute <--");
    return result;
}
示例#6
0
void XSerializer<IntVector>::deserialize(IntVector& val, XValue const& xval)
{
	Handler<XObject> obj(xval.as<XObject>());
	val.x(obj->get<decltype(val.x())>("x"));
	val.y(obj->get<decltype(val.y())>("y"));
}
示例#7
0
void BoxLevelStatistics::computeLocalBoxLevelStatistics(const BoxLevel& box_level)
{
   box_level.cacheGlobalReducedData();

   /*
    * Compute per-processor statistics.  Some quantities are readily
    * available while others are computed in the loop following.
    *
    * Aspect ratio uses a generalized formula that goes to 1 when box
    * has same length on all sides (regardless of dimension),
    * degenerates to the rectangular aspect ratio in 2D, and grows
    * appropriately for dimensions higher than 2.
    */

   d_sq.d_values[HAS_ANY_BOX] = (box_level.getLocalNumberOfBoxes() > 0);
   d_sq.d_values[NUMBER_OF_CELLS] =
      static_cast<double>(box_level.getLocalNumberOfCells());
   d_sq.d_values[NUMBER_OF_BOXES] =
      static_cast<double>(box_level.getLocalNumberOfBoxes());
   d_sq.d_values[MAX_BOX_VOL] = 0;
   d_sq.d_values[MIN_BOX_VOL] = tbox::MathUtilities<double>::getMax();
   d_sq.d_values[MAX_BOX_LEN] = 0;
   d_sq.d_values[MIN_BOX_LEN] = tbox::MathUtilities<double>::getMax();
   d_sq.d_values[MAX_ASPECT_RATIO] = 0;
   d_sq.d_values[SUM_ASPECT_RATIO] = 0;
   d_sq.d_values[SUM_SURFACE_AREA] = 0.;
   d_sq.d_values[SUM_NORM_SURFACE_AREA] = 0.;

   const BoxContainer& boxes = box_level.getBoxes();

   for (RealBoxConstIterator ni(boxes.realBegin());
        ni != boxes.realEnd(); ++ni) {

      const Box& box = *ni;
      const IntVector boxdims = box.numberCells();
      const double boxvol = static_cast<double>(boxdims.getProduct());
      const int longdim = boxdims.max();
      const int shortdim = boxdims.min();
      double aspect_ratio = 0.0;
      double surfarea = 0.;
      for (int d = 0; d < d_dim.getValue(); ++d) {
         surfarea += 2 * double(boxvol) / boxdims(d);
         double tmp = static_cast<double>(boxdims(d)) / shortdim - 1.0;
         aspect_ratio += tmp * tmp;
      }
      aspect_ratio = 1.0 + sqrt(aspect_ratio);

      d_sq.d_values[MAX_BOX_VOL] =
         tbox::MathUtilities<double>::Max(d_sq.d_values[MAX_BOX_VOL],
            boxvol);
      d_sq.d_values[MIN_BOX_VOL] =
         tbox::MathUtilities<double>::Min(d_sq.d_values[MIN_BOX_VOL],
            boxvol);

      d_sq.d_values[MAX_BOX_LEN] =
         tbox::MathUtilities<double>::Max(d_sq.d_values[MAX_BOX_LEN],
            longdim);
      d_sq.d_values[MIN_BOX_LEN] =
         tbox::MathUtilities<double>::Min(d_sq.d_values[MIN_BOX_LEN],
            shortdim);

      d_sq.d_values[MAX_ASPECT_RATIO] =
         tbox::MathUtilities<double>::Max(d_sq.d_values[MAX_ASPECT_RATIO],
            aspect_ratio);

      d_sq.d_values[SUM_ASPECT_RATIO] += aspect_ratio;
      d_sq.d_values[SUM_SURFACE_AREA] += surfarea;

   }

   /*
    * Smallest surface area possible for the number of cells perfectly
    * distributed in d_mpi.
    */
   const double ideal_surfarea =
      2 * d_dim.getValue()
      * pow(double(box_level.getGlobalNumberOfCells()) / d_mpi.getSize(),
         double(d_dim.getValue() - 1) / d_dim.getValue());

   d_sq.d_values[SUM_NORM_SURFACE_AREA] =
      d_sq.d_values[SUM_SURFACE_AREA] / ideal_surfarea;

}
示例#8
0
void TimeWarp::addAnchorPoints(const int&  startFrameX, const int& startFrameY){
	IntVector v;
	v.push_back(startFrameX);
	v.push_back(startFrameY);
	anchorPoints.push_back(v);
}