/* Widest path problem / the bottleneck shortest path problem */ int main() { int M, s, t; string s1, s2; bool first = true; while(cin >> M) { if(!first) cout << endl; first = false; vector<int> *adjacencyLists = new vector<int>[2*M+2]; // At most 2M cities! map<string,int> m; map<int,string> rev; FORI(M) { cin >> s1 >> s2; if(m.find(s1) == m.end()) { m.insert(PSI(s1, (int)m.size())); rev.insert(PIS((int)rev.size(), s1)); } if(m.find(s2) == m.end()) { m.insert(PSI(s2, (int)m.size())); rev.insert(PIS((int)rev.size(), s2)); } s = m[s1]; t = m[s2]; adjacencyLists[s].push_back(t); adjacencyLists[t].push_back(s); } // query: cin >> s1 >> s2; if(m.find(s1) == m.end()) { m.insert(PSI(s1, (int)m.size())); rev.insert(PIS((int)rev.size(), s1)); } if(m.find(s2) == m.end()) { m.insert(PSI(s2, (int)m.size())); rev.insert(PIS((int)rev.size(), s2)); } s = m[s1]; t = m[s2]; // Find maximum flow path between S and D: stack<int> path; dijkstra((int)m.size(), adjacencyLists, s, t, path); delete[] adjacencyLists; // Compute result: if(path.empty()) cout << "No route" << endl; else { while(!path.empty()) { cout << rev[path.top()] << " "; path.pop(); cout << rev[path.top()] << endl; path.pop(); } } } }
void calculateNormalized(float* values, int size) { values[0] = PSI(t,0,0); float max = values[0]; float min = values[0]; for(int i=1; i<size; ++i) { values[i] = PSI(t, i / HalfSize - HALFd, i); if(values[i] > max) max = values[i]; if(values[i] < min) min = values[i]; } for(int i=0; i<size; ++i) values[i] = (values[i] - min) / (max - min); }
/*! \brief Amplitude estimator for DESA-2 * * The function is defined as \f$A = \sqrt{\frac{\psi{(x)}}{\sin{\Omega^2}}}\f$ * * @author Eric des Courtis * @param x An array of 5 evenly spaced audio samples \f$x_0, x_1, x_2, x_3, x_4\f$. * @return The estimated amplitude. */ double ampl_estimator(double *x) { double freq_sq; freq_sq = freq_estimator(x); freq_sq *= freq_sq; return sqrt(PSI(x) / sin(freq_sq)); }
void BackboneAngles(CHAIN **Chain, int NChain) { register int Res, Cn; for( Cn=0; Cn<NChain; Cn++ ) { for( Res=0; Res<Chain[Cn]->NRes; Res++ ) { PHI(Chain[Cn],Res); PSI(Chain[Cn],Res); } } }
/* getRotation: * The function determines how much the block should be rotated * for best positioning with parent, assuming its center is at x and y * relative to the parent. * angle gives the angle of the new position, i.e., tan(angle) = y/x. * If sn has 2 nodes, we arrange the line of the 2 normal to angle. * If sn has 1 node, parent_pos has already been set to the * correct angle assuming no rotation. * Otherwise, we find the node in sn connected to the parent and rotate * the block so that it is closer or at least visible to its node in the * parent. * * For COALESCED blocks, if neighbor is in left half plane, * use unCOALESCED case. * Else let theta be angle, R = LEN(x,y), pho the radius of actual * child block, phi be angle of neighbor in actual child block, * and r the distance from center of coalesced block to center of * actual block. Then, the angle to rotate the coalesced block to * that the edge from the parent is tangent to the neighbor on the * actual child block circle is * alpha = theta + M_PI/2 - phi - arcsin((l/R)*(sin B)) * where l = r - rho/(cos phi) and beta = M_PI/2 + phi. * Thus, * alpha = theta + M_PI/2 - phi - arcsin((l/R)*(cos phi)) */ static double getRotation(block_t * sn, Agraph_t * g, double x, double y, double theta) { double mindist2; Agraph_t *subg; /* Agedge_t* e; */ Agnode_t *n, *closest_node, *neighbor; nodelist_t *list; double len2, newX, newY; int count; subg = sn->sub_graph; #ifdef OLD parent = sn->parent; #endif list = sn->circle_list; if (sn->parent_pos >= 0) { theta += M_PI - sn->parent_pos; if (theta < 0) theta += 2 * M_PI; return theta; } count = sizeNodelist(list); if (count == 2) { return (theta - M_PI / 2.0); } /* Find node in block connected to block's parent */ neighbor = CHILD(sn); #ifdef OLD for (e = agfstedge(g, parent); e; e = agnxtedge(g, e, parent)) { n = e->head; if (n == parent) n = e->tail; if ((BLOCK(n) == sn) && (PARENT(n) == parent)) { neighbor = n; break; } } #endif newX = ND_pos(neighbor)[0] + x; newY = ND_pos(neighbor)[1] + y; mindist2 = LEN2(newX, newY); /* save sqrts by using sqr of dist to find min */ closest_node = neighbor; for (n = agfstnode(subg); n; n = agnxtnode(subg, n)) { if (n == neighbor) continue; newX = ND_pos(n)[0] + x; newY = ND_pos(n)[1] + y; len2 = LEN2(newX, newY); if (len2 < mindist2) { mindist2 = len2; closest_node = n; } } /* if((neighbor != closest_node) && !ISPARENT(neighbor)) { */ if (neighbor != closest_node) { double rho = sn->rad0; double r = sn->radius - rho; double n_x = ND_pos(neighbor)[0]; if (COALESCED(sn) && (-r < n_x)) { double R = LEN(x, y); double n_y = ND_pos(neighbor)[1]; double phi = atan2(n_y, n_x + r); double l = r - rho / (cos(phi)); theta += M_PI / 2.0 - phi - asin((l / R) * (cos(phi))); } else { /* Origin still at center of this block */ double phi = atan2(ND_pos(neighbor)[1], ND_pos(neighbor)[0]); theta += M_PI - phi - PSI(neighbor); if (theta > 2 * M_PI) theta -= 2 * M_PI; } } else theta = 0; return theta; }
/* positionChildren: */ static void positionChildren (Agraph_t* g, posinfo_t* pi, posstate * stp, int length, double min_dist) { block_t *child; double childAngle, childRadius, incidentAngle; double mindistAngle, rotateAngle, midAngle = 0.0; int midChild, cnt = 0; double snRadius = stp->subtreeR; /* max subtree radius */ double firstAngle = stp->firstAngle; double lastAngle = stp->lastAngle; double d, deltaX, deltaY; childRadius = pi->scale * pi->minRadius; if (length == 1) { childAngle = 0; d = pi->diameter/(2*M_PI); childRadius = MAX(childRadius, d); d = 2*M_PI*childRadius - pi->diameter; if (d > 0) min_dist += d/pi->childCount; } else childAngle = pi->theta - pi->diameter/(2 * childRadius); if ((childRadius + pi->maxRadius) > snRadius) snRadius = childRadius + pi->maxRadius; mindistAngle = min_dist / childRadius; midChild = (pi->childCount + 1) / 2; for (child = stp->cp; child; child = child->next) { if (BLK_PARENT(child) != pi->n) continue; if (sizeNodelist(child->circle_list) <= 0) continue; incidentAngle = child->radius / childRadius; if (length == 1) { if (childAngle != 0) { if (pi->childCount == 2) childAngle = M_PI; else childAngle += incidentAngle; } if (firstAngle < 0) firstAngle = childAngle; lastAngle = childAngle; } else { if (pi->childCount == 1) { childAngle = pi->theta; } else { childAngle += incidentAngle + mindistAngle / 2; } } deltaX = childRadius * cos(childAngle); deltaY = childRadius * sin(childAngle); /* first apply the delta to the immediate child and see if we need * to rotate it for better edge link * should return the theta value if there was a rotation else zero */ rotateAngle = getRotation(child, g, deltaX, deltaY, childAngle); applyDelta(child, deltaX, deltaY, rotateAngle); if (length == 1) { childAngle += incidentAngle + mindistAngle; } else { childAngle += incidentAngle + mindistAngle / 2; } cnt++; if (cnt == midChild) midAngle = childAngle; } if ((length > 1) && (pi->n == stp->neighbor)) { PSI(pi->n) = midAngle; } stp->subtreeR = snRadius; stp->firstAngle = firstAngle; stp->lastAngle = lastAngle; }
void calculate(float* values, int size) { // calculating the wavefunction in sample points values[0] = PSI(t,0,0); for(int i=1; i<size; ++i) values[i] = PSI(t, i / HalfSize - HALFd, i); }
CPS_START_NAMESPACE /*! \file \brief Routine used internally in the DiracOpWilson class. $Id: wilson_mdag.C,v 1.2 2011-02-26 00:19:27 chulwoo Exp $ */ //-------------------------------------------------------------------- // CVS keywords // // $Author: chulwoo $ // $Date: 2011-02-26 00:19:27 $ // $Header: /home/chulwoo/CPS/repo/CVS/cps_only/cps_pp/src/util/dirac_op/d_op_wilson/sse/wilson_mdag.C,v 1.2 2011-02-26 00:19:27 chulwoo Exp $ // $Id: wilson_mdag.C,v 1.2 2011-02-26 00:19:27 chulwoo Exp $ // $Name: not supported by cvs2svn $ // $Locker: $ // $Revision: 1.2 $ // $Source: /home/chulwoo/CPS/repo/CVS/cps_only/cps_pp/src/util/dirac_op/d_op_wilson/sse/wilson_mdag.C,v $ // $State: Exp $ // //-------------------------------------------------------------------- CPS_END_NAMESPACE #include <util/data_types.h> #include <util/wilson.h> #include <util/dirac_op.h> CPS_START_NAMESPACE //! Access to the elements of the \e SU(3) matrix /*! Gets the element of the \e SU(3) matrix \e u with row \e row, column \e col and complex component \e d */ #define U(r,row,col,d,n,cb) *(u+(r+2*(row+3*(col+3*(d+4*(n+vol[0]*(cb))))))) //! Access to the elements of a spinor vector. /*! Gets the element of the spinor \e psi with spin \e s, colour \e c and complex component \e r */ #define PSI(r,c,s,n) *(psi+(r+2*(c+3*(s+4*(n))))) //! As above, but the vector is called chi #define CHI(r,c,s,n) *(chi+(r+2*(c+3*(s+4*(n))))) #define TMP1(r,c,s,n) *(tmp1+(r+2*(c+3*(s+4*(n))))) void wilson_mdag(IFloat *chi_f, IFloat *u_f, IFloat *psi_f, IFloat kappa_f, Wilson *wilson_p) { IFloat *tmp1_f; int vol; int r, c, s, n; /*--------------------------------------------------------------------------*/ /* Initializations */ /*--------------------------------------------------------------------------*/ vol = wilson_p->vol[0]; tmp1_f = wilson_p->af[0]; Float *chi = (Float *) chi_f; Float *psi = (Float *) psi_f; Float kappa = Float(kappa_f); /*--------------------------------------------------------------------------*/ /* DslashDag_E0 */ /*--------------------------------------------------------------------------*/ wilson_dslash(tmp1_f, u_f, psi_f, 1, 1, wilson_p); /*--------------------------------------------------------------------------*/ /* DslashDag_0E */ /*--------------------------------------------------------------------------*/ wilson_dslash(chi_f, u_f, tmp1_f, 0, 1, wilson_p); /*--------------------------------------------------------------------------*/ /* [1_OO - kappa * DslashDag_0E * DslashDag_E0] ] */ /*--------------------------------------------------------------------------*/ for(n=0;n<vol;n++){ for(s=0;s<4;s++){ for(c=0;c<3;c++){ for(r=0;r<2;r++){ CHI(r,c,s,n) = ( PSI(r,c,s,n) - kappa*kappa * CHI(r,c,s,n)); } } } } DiracOp::CGflops += vol*24*2; }
void init(int n, int m, double *par, double *u, double *t, double *s){ // declare variables int i, j; vector<double> T(m), U(m), S(m*n), Rtube(m); double a, b; // major and minor axes int info; double v = par[0]; // reduced volume double kb = par[1]; // bending modulus (scaled by dp*a^3) double alph = par[2]; // taper angle of tube wall double R0 = par[3]; // tube radius at center-of-mass axial position (scaled by a) double xcom = par[4]; // center-of-mass position // = time integral of center-of-mass translational speed double tana = gsl_sf_sin(alph)/gsl_sf_cos(alph); // get surface area and volume double area = 4.0*M_PI; double vlme = 4.0*M_PI*v/3.0; // get spheroid vector<double> Sarc(m), R(m), X(m), XCOM(m), CS(m), CPHI(m), THET(m), PSI(m), A(m), V(m); proAxes(area, vlme, 1.01, 1.0, a, b, info); if (info == 1) proAxes(area, vlme, 1.5, 1.0, a, b, info); proShape(m, a, b, Sarc.data(), X.data(), R.data(), XCOM.data(), CS.data(), CPHI.data(), PSI.data(), THET.data(), A.data(), V.data()); // for (i = 0; i < m; i++){ // cout << XCOM[i] << endl; // } double Stot = Sarc[m-1]; // get tube radius for (i = 0; i < m; i++){ Rtube[i] = R0 - tana*X[i]; } // polynomial expressions for p and tau (from static solution) double p, sig; p = - 0.39632; p += 2.89243*v; p += - 8.71787*v*v; p += 13.91363*v*v*v; p += -12.41387*v*v*v*v; p += 5.87473*v*v*v*v*v; p += -1.15262*v*v*v*v*v*v; p *= 1e5*kb; sig = 1.2935; sig += - 9.3499*v; sig += 27.9266*v*v; sig += -44.1844*v*v*v; sig += 39.0880*v*v*v*v; sig += -18.3432*v*v*v*v*v; sig += 3.5688*v*v*v*v*v*v; sig *= 1e4*kb; for (i = 0; i < m; i++){ t[i ] = Sarc[i]/Stot; u[i ] = 0.0; s[i*n + 0 ] = R [i]; s[i*n + 1 ] = X [i]; s[i*n + 2 ] = PSI[i]; s[i*n + 3 ] = CS [i]; s[i*n + 4 ] = 0.0 ; // transverse shear tension s[i*n + 5 ] = p ; s[i*n + 6 ] = sig ; s[i*n + 7 ] = A [i]; s[i*n + 8 ] = V [i]; s[i*n + 9 ] = 0.0 ; // leakback flux s[i*n + 10] = Rtube[i]; s[i*n + 11] = XCOM[i]; s[i*n + 12] = 0.0 ; // center of mass speed s[i*n + 13] = Stot ; } // read input file int id[3]; id[0] = 90; // reduced volume id[1] = 80; // confinement id[2] = 0 ; // bending modulus readInput(n, m, id, T.data(), S.data()); for (i = 0; i < m; i++){ t[i] = T[i]; for (j = 0; j < n; j++){ s[i*n + j] = S[i*n + j]; } } // // for debugging // for (i = 0; i < m; i++){ // printf("%.4f ", T[i]); // for (j = 0; j < n; j++) // printf("%.4f ", S[i*n + j]); // printf("\n"); // } // // get critical confinement parameter and set nominal radius // getCritCf(v, crit); // a = 0.01*double(conf)*crit; // // area = 4.0*M_PI*a*a; // vlme = (4.0/3.0)*M_PI*a*a*a*(0.01*double(v)); // proShape(m, a, b, // double &S, double *t, double *x, double *r, // double *cs, double *cphi, double *psi, // double *A, double *V){ // b > a // // read file // readEquil(n, m, 90, conf, T.data(), S.data()); // //readOutput(n, m, v, conf-1, Ca, T.data(), S.data()); // initialize using slightly smaller vesicle (useful at high Ca) // // // copy abscissa and solution vectors // for (i = 0; i < m; i++){ // t[i] = T[i]; // for (j = 0; j < n; j++){ // s[i*n + j] = S[i*n + j]; // } // } }
nodelist_t *layout_block(Agraph_t * g, block_t * sn, double min_dist) { Agnode_t *n; Agraph_t *copyG, *tree, *subg; nodelist_t *longest_path; nodelistitem_t *item; int N, k; double theta, radius, largest_node; largest_node = 0; subg = sn->sub_graph; block_graph(g, sn); /* add induced edges */ copyG = remove_pair_edges(subg); tree = spanning_tree(copyG); longest_path = find_longest_path(tree); place_residual_nodes(subg, longest_path); /* at this point, longest_path is a list of all nodes in the block */ /* apply crossing reduction algorithms here */ longest_path = reduce_edge_crossings(longest_path, subg); N = sizeNodelist(longest_path); largest_node = largest_nodesize(longest_path); /* N*(min_dist+largest_node) is roughly circumference of required circle */ if (N == 1) radius = 0; else radius = (N * (min_dist + largest_node)) / (2 * PI); for (item = longest_path->first; item; item = item->next) { n = item->curr; if (ISPARENT(n)) { /* QUESTION: Why is only one parent realigned? */ realignNodelist(longest_path, item); break; } } k = 0; for (item = longest_path->first; item; item = item->next) { n = item->curr; POSITION(n) = k; PSI(n) = 0.0; theta = k * ((2.0 * PI) / N); ND_pos(n)[0] = radius * cos(theta); ND_pos(n)[1] = radius * sin(theta); k++; } if (N == 1) sn->radius = largest_node / 2; else sn->radius = radius; sn->rad0 = sn->radius; /* initialize parent pos */ sn->parent_pos = -1; agclose(copyG); return longest_path; }