本文整理汇总了C++中vd::size方法的典型用法代码示例。如果您正苦于以下问题:C++ vd::size方法的具体用法?C++ vd::size怎么用?C++ vd::size使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类vd
的用法示例。
在下文中一共展示了vd::size方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: average
double average( vd v)
{
vd::iterator it;
double sum = 0.0;
if ( v.size() == 0) return(0.0);
for(it = v.begin(); it < v.end(); ++it)
sum += *it;
return(sum/v.size());
}
示例2: solve
//a1x1+a2x2+a3=0
//b1x1+b2x2+b3=0
vctr solve(vd &a, vd &b)
{
assert(a.size()==b.size()&&a.size()==3);
if(fabs(b[0])>fabs(a[0]))swap(a,b);
assert(fabs(a[0])>EPS);
double k=b[0]/a[0];
rep(i,3)b[i]-=a[i]*k;
assert(fabs(b[1])>EPS);
double x2=-b[2]/b[1];
double x1=-(a[2]+a[1]*x2)/a[0];
return vctr(x1,x2);
}
示例3: constructPoints
void constructPoints(const vector<Edge> &edges, const vd &mesh,
vector<Point> &points, vvi &edge2point) {
points.clear();
for (int x = 2; x <= 8; x += 2) {
for (int y = 2; y <= 8; y += 2) {
for (int z = 2; z <= 8; z += 2) {
D3 p(x, y, z);
if (isOneOfEndPoint(p, edges)) {
points.push_back(Point(p));
for (int i = 0; i < edges.size(); i++) {
if (edges[i].src == p) {
addPoint(points, edge2point, i);
} else if (edges[i].dst == p) {
addPoint(points, edge2point, i);
}
}
}
}
}
}
for (int i = 0; i < edges.size(); i++) {
D3 p = edges[i].src;
D3 v = edges[i].dst - edges[i].src;
for (int j = 0; j < mesh.size(); j++) {
points.push_back(Point(p + mesh[j]*v));
addPoint(points, edge2point, i);
}
}
}
示例4: stddev
double stddev( vd v, double avg)
{
vd::iterator it;
double sumSq = SumSquaredDifferences(v, avg);
return( stddev(sumSq,v.size()) );
}
示例5: printTask
void printTask(const vvd& a, const vd& b, const vd& c, const std::string& filename = "task.txt")
{
size_t n = c.size();
size_t m = a.size();
std::ofstream out(filename);
for (size_t i = 0; i < n; ++i)
{
auto& t = c[i];
if (std::abs(t) < EPS)
{
continue;
}
if (t > 0)
{
out << "+\t" << t;
}
if (t < 0)
{
out << "-\t" << -t;
}
out << " * x" << i + 1 << "\t";
}
out << "-----> MAX\n";
for (size_t i = 0; i < m; ++i)
{
out << "x" << n + i + 1 << "\t=\t" << b[i] << "\t";
for (size_t j = 0; j < n; ++j)
{
auto t = -a[i][j];
if (std::abs(t) < EPS)
{
continue;
}
if (t > 0)
{
out << "+\t" << t;
}
if (t < 0)
{
out << "-\t" << -t;
}
out << " * x" << j + 1 << "\t";
}
out << endl;
}
}
示例6: operator
double pcet::operator()(const vd& v) {
double xn1 = v[1],pn1 = v[2],xn2 = v[3],pn2 = v[4],qr = v[5],pr = v[6];
double n1=e.n(xn1,pn1),n2=e.n(xn2,pn2);
double h_bath=0.0;
for (size_t i = 7; i < v.size(); ++(++i)) {
size_t ib=(i-7)/2;
double mw2=bp.m*pow(bw[ib],2);
h_bath+= v[i+1]*v[i+1]*0.5/bp.m
+ mw2*0.5*pow((v[i]+n1*bc[ib]/mw2),2);
}
double h11 = sp.eps_r + sp.w_r*sp.w_r*sp.m*pow((qr-sp.qr_initial),2)*0.5;
double h22 = sp.eps_k + sp.w_k*sp.w_k*sp.m*pow((qr-sp.qr_initial),2)*0.5;
double h12 = sp.delta;
double h_avg= (h11+h22)*0.5;
double h_delta= h11-h22;
return pr*pr*0.5/sp.m+
h_avg+
h_delta*(n1-n2)*0.5+
sp.delta*(xn1*xn2+pn1*pn2) + h_bath;
//2*delta*sqrt((n1+e.n_shift)*(n2+e.n_shift))*(xn1*xn2+pn1*pn2); ///> TODO
}
示例7: print
void print(const vd &a){rep(i,a.size())printf("%.2lf%c",a[i],i==a.size()-1?'\n':' ');}
示例8: zero_out
void zero_out(vd & v, vd & u, int j)
{
if(zero(u[j])) return;
double r = u[j] / v[j];
range(k, j, v.size()) u[k] -= r * v[k];
}
示例9: normalise
void normalise(vd & v, int j)
{
double x = v[j];
range(k, j, v.size()) v[k] /= x;
}
示例10: printResult
void printResult(vd &v){
int n = v.size();
printf("Xn: Yn:\n");
for(int i=0; i<n; i++)
printf("%.2f %.4f\n", v[i].first, v[i].second);
}
示例11: fwht_rev
vd fwht_rev(vd& a) {
vd res = fwht(a);
F0R(i,sz(res)) res[i] /= a.size();
return res;
}
示例12: BellmanFordMoore
//shortest path from a node n to every other node:
//this is for any graphs even ones that have negative weights -- can detect negative cycles
//for every vertex, relax E times
//as an optimization we use a queue to store vertices that changed
//and relax paths only from that queue
//to detect negative loops can check if node n gets updated on any the n-th iteration
int BellmanFordMoore(const graphtp & g, vd & D, int src)
{
int comparisons = 0;
vi visited(g.size());
std::vector<edge> P(g.size()); //parent node for node e.to is e.from
for(vd::iterator it = D.begin(); it != D.end(); ++it)
*it = INFINITY;
D[src] = 0;
si lastupdated;
//keep a queue (set) of vertices (nodes) that were updated last time around
//do the relaxation V times
for(size_t i = 0; i < g.size(); i++) {
lastupdated.insert(i);
}
//without optimization loop would be: for(int i = 0; i < g.size(); i++)
size_t counter = 0;
while(!lastupdated.empty()) {
counter++;
si newlast;
//visit and relax all edges (two for loopxs needed to visit all edges)
for(si::iterator jt = lastupdated.begin();jt != lastupdated.end(); jt++)
{
int v = *jt;
out("next to work on is %d\n", v);
for(ve::const_iterator it = g[v].begin(); it != g[v].end(); ++it)
{
float dist = D[v] + it->weight;
assert(v == it->from && "not the same node");
if(D[it->to] > dist) { //this is the relaxation step
out("counter %d, it->to %d\n", counter, it->to);
if(counter >= g.size()) {
//we should not update a node in a stage greater than sz
printf("negative cycles exists distance %d to %d is %f\n", v, it->to, dist);
//need to trace back from P[v]
//printSP(P, it->to, v);
printSP(P, v, it->to);
printf("\n");
return -1;
}
D[it->to] = dist;
P[it->to] = *it;
newlast.insert(it->to); //track which changed
out("new distance %d to %d is %f\n", v, it->to, dist);
}
}
}
lastupdated = newlast;
}
for(size_t i = 0; i < D.size(); i++) {
printf("%d -> %d sp=%.2f ", src, i, D[i]);
printSP(P, i, src);
printf("\n");
}
out("comparisons %d\n", comparisons);
return 0;
}
示例13: bitstream
vi bitstream(vd in)
{
vi out(in.size());
for (int n=0; n<in.size(); n++) {out[n]=(copysign(1,in[n])+1)/2;}
return out;
}