bool CParamManager::SetParam(VP& vp, char* pa) { if ( pa == NULL ) return false; string name(pa); string value; string::size_type pos = name.find(':'); if ( pos == string::npos ) return false; value = name.substr( pos+1, name.length()-pos ); name = name.substr( 0, pos ); VP_IT it = vp.find(name); if ( it == vp.end() ) return false; _CParam* p = (*it).second; switch ( p->type ) { case PT_INT: *((int*)p->value) = CCStringMake(value.c_str())->intValue(); break; case PT_FLOAT: *((float*)p->value) = CCStringMake(value.c_str())->floatValue(); break; default: return false; } return true; }
VP solve(vector<Line> line) { sort(line.begin(), line.end(), cmp()); int n = unique(line.begin(), line.end(), kequal) - line.begin(); assert(n > 2); int head = 0, tail = 1; que[0] = line[0]; que[1] = line[1]; VP ret; for (int i = 2; i < n; i++) { if (fabs((que[tail].e - que[tail].s).det(que[tail - 1].e - que[tail - 1].s)) < eps || fabs((que[head].e - que[head].s).det(que[head + 1].e - que[head + 1].s)) < eps) { return ret; } while (head < tail && ((isLL(que[tail], que[tail - 1])[0] - line[i].s) .det(line[i].e - line[i].s)) > eps) tail--; while (head < tail && ((isLL(que[head], que[head + 1])[0] - line[i].s) .det(line[i].e - line[i].s)) > eps) head++; que[++tail] = line[i]; } while (head < tail && ((isLL(que[tail], que[tail - 1])[0] - que[head].s) .det(que[head].e - que[head].s)) > eps) tail--; while (head < tail && ((isLL(que[head], que[head + 1])[0] - que[tail].s) .det(que[tail].e - que[tail].s)) > eps) head++; if (tail <= head + 1) return ret; for (int i = head; i < tail; i++) { ret.push_back(isLL(que[i], que[i + 1])[0]); } if (head < tail + 1) ret.push_back(isLL(que[head], que[tail])[0]); return ret; }
void test_container_with (VP &v1) const { // Container type tests in addition to expression types // Insert and erase v1.insert_element (0,0, 55); v1.erase_element (1,1); v1.clear (); }
int main(int argc, char *argv[]) { Point p; int hi; while(4 == scanf("%d%d%d%d",&N,&M,&S,&V)) { for(int i = 0; i < N; ++i) edges[i].clear(); v_left = VI(N + 1, -1); v_right = VI(M + 1, -1); gophers.clear(); holes.clear(); hi = (V*S)*(V*S); for(int i = 0; i < N; ++i) { scanf("%lf%lf",&p.first,&p.second); gophers.push_back(p); } for(int i = 0; i < M; ++i) { scanf("%lf%lf",&p.first,&p.second); holes.push_back(p); } for(int i = 0; i < N; ++i) { for(int j = 0; j < M; ++j) { if(dist(gophers[i],holes[j]) < hi) edges[i].push_back(j); } } printf("%d\n",match()); } return 0; }
int main() { #ifndef ONLINE_JUDGE freopen("in.txt", "r", stdin); #endif int xa,ya,xb,yb; cin>>xa>>ya>>xb>>yb; for(int i=min(xa,xb);i<=max(xa,xb);i++) { for(int j=min(ya,yb);j<=max(ya,yb);j++) { if(i==xa|| i==xb || j==ya|| j==yb) v.pb(pp(i,j)); } } //cout<<v.size()<<endl; v.erase(unique(v.begin(),v.end()),v.end()); int c=0; int n;s(n); rep(i,n) { int x,y,r; s(x);s(y);s(r); ar1[i]=x;ar2[i]=y;ar3[i]=r; }
VP isLL(CP p1, CP p2, CP q1, CP q2){ //二直线交点,无则返回空vector //返回空时有共线与相离的区别,用(p2 - p1).det(q1 - p1) == 0判断 VP ret; T d = (q2 - q1).det(p2 - p1); if (fabs(d) < eps) return ret; ret.push_back(p1 + (p2 - p1) * ((q2 - q1).det(q1 - p1) / d)); return ret; }
VP ConvexCut(const VP &ps, L l) { VP Q; for (int i = 0; i < (int)ps.size(); i++) { P A = ps[i], B = ps[(i+1)%ps.size()]; if (ccw(l.a, l.b, A) != -1) Q.push_back(A); if (ccw(l.a, l.b, A) * ccw(l.a, l.b, B) < 0) Q.push_back(is_ll((L){A, B}, l)); } return Q; }
VP ConvexHull(VP ps) { int n = ps.size(); int k = 0; sort(ps.begin(), ps.end()); VP ch(2 * n); for (int i = 0; i < n; ch[k++] = ps[i++]) while (k >= 2 && ccw(ch[k - 2], ch[k - 1], ps[i]) <= 0) --k; for (int i = n - 2, t = k + 1; i >= 0; ch[k++] = ps[i--]) while (k >= t && ccw(ch[k - 2], ch[k - 1], ps[i]) <= 0) --k; ch.resize(k - 1); return ch; }
ld max_distance(const VP &ps) { assert (ps.size() > 1); VP g = ConvexHull(ps); int n = g.size(), a = 0, b = 1; ld res = abs(g[0] - g[1]); while (a < n) { P p1 = g[a%n], p2 = g[(a+1)%n]; P q1 = g[b%n], q2 = g[(b+1)%n]; if (arg((p2 - p1) / (q1 - q2)) > 0) ++b; else ++a; res = max(res, abs(p1 - q1)); } return res; }
void calculatePaths() { for (int i = 0; i < paths.size(); i++) { if (paths[i].first == 1) { depth = 0; for (int j = 0; j < paths.size(); j++) { //cout << j << endl; pair<int,int> speeds = followPath(i, j); bessieSpeeds.pb(speeds.bessie); elsieSpeeds.pb(speeds.elsie); } } } }
void split_route(vector<Segment> &vs,VR &nodes,int idx, int n1, int n2){ ParamEdge e=vs[idx].edge; debugline(e.from(),e.to(),255,0,0,true); double minp=DBL_MAX; int minidx=-1; for (int j=0,n=nodes.size();j<n;j++){ if (j==n1 || j==n2) continue; if (e.cross(nodes[j])){ if (nodes[j].contains(e.from())) continue; if (nodes[j].contains(e.to())) continue; double p=e.cross_param_smallest(nodes[j]); if (p<minp){ minp=p; minidx=j; } } } if (minidx<0) return ; Point dc=e.dist_vec(nodes[minidx].center()); if (dc.is_null()){ dc=to_left(e.unit(),PI/2); // minidxust choose a side } VP pts; Point r=e.dist_vec(nodes[minidx].TL()); if (scalar(r,dc)<0) pts.push_back(nodes[minidx].TL()); r=e.dist_vec(nodes[minidx].TR()); if (scalar(r,dc)<0) pts.push_back(nodes[minidx].TR()); r=e.dist_vec(nodes[minidx].BL()); if (scalar(r,dc)<0) pts.push_back(nodes[minidx].BL()); r=e.dist_vec(nodes[minidx].BR()); if (scalar(r,dc)<0) pts.push_back(nodes[minidx].BR()); if (pts.size()==0) { printf("Ups, no points on smaller side of edge/node cut area"); return; } if (pts.size()>2 ) throw "expected 1 or 2 points"; vector<Segment> vsnew; int idxlast=idx+1; if (pts.size()==1){ vsnew.push_back(Segment(ParamEdge(e.from(),pts[0]),vs[idx].first,false)); vsnew.push_back(Segment(ParamEdge(pts[0],e.to()),false,vs[idx].last)); } else if (pts.size()==2) { if (norm(pts[0]-e.from())>norm(pts[1]-e.from())){ // do nearest point first swap(pts[0],pts[1]); } vsnew.push_back(Segment(ParamEdge(e.from(),pts[0]),vs[idx].first,false)); vsnew.push_back(Segment(ParamEdge(pts[0],pts[1]),false,false)); vsnew.push_back(Segment(ParamEdge(pts[1],e.to()),false,vs[idx].last)); idxlast++; } vs.erase(vs.begin()+idx); vs.insert(vs.begin()+idx,vsnew.begin(),vsnew.end()); split_route(vs,nodes,idxlast,minidx,n2); split_route(vs,nodes,idx,n1,minidx); // new overlaps could be introduced after makeing a kink into the line }
void cut_convex(VP& a, Point p1, Point p2) { VP b; repn(i, sz(a)) { Point a1 = a[i], a2 = a[(i + 1) % a.size()]; double m1 = mult(p1, p2, a1); double m2 = mult(p1, p2, a2); if(sgn(m1) * sgn(m2) < 0) { Point tmp; tmp.x = (a1.x * m2 - a2.x * m1) / (m2 - m1); tmp.y = (a1.y * m2 - a2.y * m1) / (m2 - m1); b.push_back(tmp); } if(sgn(m2) >= 0) b.push_back(a2); }
VP isCL(CP c, double r, CP p1, CP p2) { //返回值按到p1的距离从小到大排列 double x = (p1 - c).dot(p2 - p1); double y = (p2 - p1).abs2(); double d = x * x - y * ((p1 - c).abs2() - r * r); if (d < -eps) return VP(0); if (d < 0) d = 0; Point q1 = p1 - (p2 - p1) * (x / y); Point q2 = (p2 - p1) * (sqrt(d) / y); VP ret; ret.push_back(q1 - q2); ret.push_back(q1 + q2); return ret; }
int calcPos(VI &data,VVI &g,int node) { int ret=-1; VI wc(n , 0); VI pos(n , -1); int curNode = data[n-1]; for(int i = sz(data)-2 ; i>=0 ; i--) { if(g[curNode][data[i]]) { wc[curNode]++; } else { wc[data[i]]++; curNode = data[i]; } } for(int i = 0 ; i<n ; i++) cout<<i <<" wc "<<wc[i]<<endl; pos[curNode] = 1; VP slist; int idx = 2; for(int i = 0 ; i<n ; i++) { if(i==curNode) continue; slist.push_back({ wc[i] , i }); } sort(slist.begin() , slist.end()); for(int i = sz(slist)-1 ; i>=0 ; i--) { if(i==(sz(slist)-1) || (slist[i].x!=slist[i+1].x)) pos[slist[i].y] = idx++; else pos[slist[i].y] = pos[slist[i+1].y]; } for(int i = 0 ; i<n ; i++) { cout<<i<<" pos "<<pos[i]<<endl; } return pos[node]; }
double areaCP(VP ps, Point center, double r) { int n = ps.size(); double ans = 0; for (int i = 0; i < n; i++) { ans += areaCT(ps[i], ps[(i + 1) % n], center, r); } return ans; }
double areaCT(Point p1, Point p2, double r) { VP qs = isCL(0, r, p1, p2); if (qs.size() == 0) return r * r * rad(p1, p2) / 2; bool b1 = p1.abs() > r + eps, b2 = p2.abs() > r + eps; if (b1 && b2) { if ((p1 - qs[0]).dot(p2 - qs[0]) < eps && (p1 - qs[1]).dot(p2 - qs[1]) < eps) { return (r * r * (rad(p1, p2) - rad(qs[0], qs[1])) + qs[0].det(qs[1])) / 2; } else { return r * r * rad(p1, p2) / 2; } } else if (b1) { return (r * r * rad(p1, qs[0]) + qs[0].det(p2)) / 2; } else if (b2) { return (r * r * rad(qs[1], p2) + p1.det(qs[1])) / 2; } else { return p1.det(p2) / 2; } }
void Polygon::CreateFromPoints(const VP& SomePoints) { m_pPosition = Sum(SomePoints)/SomePoints.size(); m_vPoints = ConvexHull(SomePoints); for (auto& m_vPoint : m_vPoints) { m_vPoint -= m_pPosition; } }
VP convexCut(VP ps, CP p1, CP p2) { //返回凸多边形被有向直线p1p2切割后左半部分, 可改为在线半平面交 int n = ps.size(); VP ret(0); for (int i = 0; i < n; i++) { int d1 = sgn((p2 - p1).det(ps[i] - p1)); int d2 = sgn((p2 - p1).det(ps[(i + 1) % n] - p1)); if (d1 >= 0) ret.push_back(ps[i]); if (d1 * d2 < 0) ret.push_back(isLL(p1, p2, ps[i], ps[(i + 1) % n])[0]); } return ret; }
int main() { int tcase,cas=1; cin>>tcase; while(tcase--) { cin>>n; VVI g(n , VI(n , 0)); for(auto &x: g) for(auto &y: x) cin>> y; VP slist; for(int i = 0 ; i<n ; i++) { int cnt = 0; for(int j =0 ; j<n ; j++) cnt+= g[i][j]; slist.push_back({cnt , i}); } sort(slist.begin() , slist.end()); VP sol; for(int i = 0 ; i<n ; i++) { int mx = posMax(g , slist , i); int mn = posMin(g , slist , i); cout<<i<<" "<<mx<<" "<<mn<<endl; } } return 0; }
VP solve(VP ps) { int n = ps.size(), k = 0; if (n <= 1) { return ps; } sort(ps.begin(), ps.end(), cmp()); VP qs(n * 2); for (int i = 0; i < n; qs[k++] = ps[i++]) { while(k > 1 && (qs[k - 1] - qs[k - 2]).det(ps[i] - qs[k - 1]) < eps) { k--; } } for (int i = n - 2, t = k; i >= 0; qs[k++] = ps[i--]) { while (k > t && (qs[k - 1] - qs[k - 2]).det(ps[i] - qs[k - 1]) < eps) { k--; } } qs.resize(k - 1); return qs; }
///******************************************************** void draw(){ //glut 回调函数 double maxX=-100000,minX=-maxX; double maxY=-100000,minY=-maxY; for(int i=0;i<city.size();i++){ maxX=max(maxX,city[i].first); minX=min(minX,city[i].first); maxY=max(maxY,city[i].second); minY=min(minY,city[i].second); } double aveX=(minX+maxX)/2, _X=1.2*(aveX-minX); double aveY=(minY+maxY)/2, _Y=1.2*(aveY-minY); //等比例缩放 glClearColor(1.0, 1.0 , 1.0, 0); //白板 glClear(GL_COLOR_BUFFER_BIT); //清位 glPointSize(10); //设置点的大小,这个必须在模式选择之前 glLineWidth(5); //设置线宽 glBegin(GL_POINTS); //画点 for(int i=0;i<city.size();i++){ glColor3f(1,0,0); double x=(city[i].first-aveX)/_X; double y=(city[i].second-aveY)/_Y; glVertex2f(x,y); } glEnd(); glBegin(GL_LINE_LOOP); //画线 for(int i=0;i<city.size();i++){ glColor3f(0,1,0); double x=(city[ permut[i] ].first- aveX)/_X; //permutation double y=(city[ permut[i] ].second-aveY)/_Y; glVertex2f(x,y); } glEnd(); glutSwapBuffers(); }
int main() { ifstream fin("meeting.in"); fin >> N >> M; cout << N << endl; cout << endl; for (int i = 0; i < M; i++) { fin >> A >> B >> C >> D; paths.pb(mp(A,B)); speeds.pb(mp(C,D)); } fin.close(); calculatePaths(); for (int i = 0; i < bessieSpeeds.size(); i++) { cout << "Bessie: " << bessieSpeeds[i] << endl; cout << elsieSpeeds[i] << endl; } for (int i = 0; i < bessieSpeeds.size(); i++) { if (bessieSpeeds[i] > leastTime) break; for (int j = 0; j < elsieSpeeds.size(); j++) { if (bessieSpeeds[i] == elsieSpeeds[j]) { if (bessieSpeeds[i] < leastTime) { leastTime = bessieSpeeds[i]; break; } } } } ofstream fout("meeting.out"); cout << leastTime << endl; if (leastTime != 1000000) { fout << leastTime << endl; } else fout << "IMPOSSIBLE" << endl; fout.close(); return 0; }
int main(){ srand(time(NULL)); //没有这个每次的运行结果将相同 int N,T,S; double pc,pm; printf("注意: 此系统数据都是随机生成的,所以每次运行的城市坐标可能不同,结果也可能不同!!\n\n"); printf("请输入TSP问题城市数目,GA算法迭代次数,种群大小,交叉概率,变异概率\n"); while(cin>>N>>T>>S>>pc>>pm){ clock_t Time=clock(); city.clear(); printf("城市坐标如下:\n"); for(int i=0;i<N;i++){ //坐标随机生成 double a=rand()%5000, b=rand()%5000; city.push_back(Point(a,b)); printf("(%5.0lf,%5.0lf)\n",a,b); } double mi=1000000000.0; //记录最小距离和 Population p(N,S,pc,pm); //产生种群 for(int i=0;i<T;i++){ //迭代T次 p.getNext(); mi=min(mi,p.getBest().dis); //更新最小距离和 } permut=p.getBest().v; //终止状态种群的最佳个体 printf("路径为: "); for(int i=0;i<permut.size();i++){ if( i!=0 ) printf("-->"); printf("%d",permut[i]); if( i==permut.size()-1 ) puts(""); } printf("计算中出现过的最小距离和为: %.1lf 最终距离和为: %.1lf\n",mi,p.getBest().dis); printf("计算耗时: %.3lf 秒\n",(clock()-Time)/1000.0); OpenGLInit(); glutDisplayFunc(draw); glutMainLoop(); } }
int contains(VP ps, CP q) { int n = ps.size(); int res = -1; for (int i = 0; i < n; i++) { Point a = ps[i] - q, b = ps[(i + 1) % n] - q; if (a.y > b.y) { Point t = a; a = b; b = t; } if (a.y < eps && b.y > eps && a.det(b) > eps) { res = -res; } if (abs(a.det(b)) < eps && a.dot(b) < eps) { return 0; } } return res; }
double convexDiameter(VP ps) { int n = ps.size(); int is = 0, js = 0; for (int i = 1; i < n; i++) { if (ps[i].x > ps[is].x) is = i; if (ps[i].x < ps[js].x) js = i; } double maxd = (ps[is] - ps[js]).abs(); int i = is, j = js; do { if ((ps[(i + 1) % n] - ps[i]).det(ps[(j + 1) % n] - ps[j]) >= 0) { j = (j + 1) % n; } else { i = (i + 1) % n; } maxd = max(maxd, (ps[i] - ps[j]).abs()); } while (i != is || j != js); return maxd; }
VP cal_convex(VP a) { VP r; sort(all(a)); for(const auto& p: a) { while(sz(r)>1 && cross(r[sz(r)-2], r[sz(r)-1], p)<=0) r.pop_back(); r.pb(p); } int K=sz(r); reverse(all(a)); for(const auto& p: a) { while(sz(r)>K && cross(r[sz(r)-2], r[sz(r)-1], p)<=0) r.pop_back(); r.pb(p); } r.pop_back(); return r; }
pair<int,int> followPath(int path, int startDepth) { depth++; if (depth > 17) return mp(1000000, 1000000); int bessieTime = speeds[path].bessie, elsieTime = speeds[path].elsie; int leastTimeBessie = 1000000, leastTimeElsie = 1000001; cout << paths[path].second << endl; if (paths[path].second == N - 1) { cout << path << endl; return mp(bessieTime, elsieTime); } for (int i = startDepth; i < paths.size(); i++) { if (path != i && paths[path].second == paths[i].first) { bessieTime = speeds[path].bessie; elsieTime = speeds[path].elsie; pair<int,int> speeds = followPath(i, 0); bessieTime += speeds.bessie; elsieTime += speeds.elsie; if (bessieTime < leastTimeBessie) leastTimeBessie = bessieTime; if (elsieTime < leastTimeElsie) leastTimeElsie = elsieTime; } } return mp(leastTimeBessie, leastTimeElsie); }
Polygon::Polygon(const VP& SomePoints, bool alreadyconvex) { assert(!SomePoints.empty()); // cout << "Polygon::cctor" << endl; if (alreadyconvex) { m_vPoints = SomePoints; } else { m_vPoints = ConvexHull(SomePoints); } // cout << "getting center of mass" << endl; m_pPosition = Sum(m_vPoints)/m_vPoints.size(); // cout << "substracting" << endl; for (auto& m_vPoint : m_vPoints) { m_vPoint -= m_pPosition; } // cout << "done" << endl; }
void operator () (VP &v1, VP &v2, VP &v3) const { try { value_type t; size_type i; real_type n; // Copy and swap initialize_vector (v1); initialize_vector (v2); v1 = v2; std::cout << "v1 = v2 = " << v1 << std::endl; v1.assign_temporary (v2); std::cout << "v1.assign_temporary (v2) = " << v1 << std::endl; v1.swap (v2); std::cout << "v1.swap (v2) = " << v1 << " " << v2 << std::endl; // Unary vector operations resulting in a vector initialize_vector (v1); v2 = - v1; std::cout << "- v1 = " << v2 << std::endl; v2 = ublas::conj (v1); std::cout << "conj (v1) = " << v2 << std::endl; // Binary vector operations resulting in a vector initialize_vector (v1); initialize_vector (v2); v3 = v1 + v2; std::cout << "v1 + v2 = " << v3 << std::endl; v3 = v1 - v2; std::cout << "v1 - v2 = " << v3 << std::endl; // Scaling a vector t = N; initialize_vector (v1); v2 = value_type (1.) * v1; std::cout << "1. * v1 = " << v2 << std::endl; v2 = t * v1; std::cout << "N * v1 = " << v2 << std::endl; initialize_vector (v1); v2 = v1 * value_type (1.); std::cout << "v1 * 1. = " << v2 << std::endl; v2 = v1 * t; std::cout << "v1 * N = " << v2 << std::endl; // Some assignments initialize_vector (v1); initialize_vector (v2); #ifdef BOOST_UBLAS_USE_ET v2 += v1; std::cout << "v2 += v1 = " << v2 << std::endl; v2 -= v1; std::cout << "v2 -= v1 = " << v2 << std::endl; #else v2 = v2 + v1; std::cout << "v2 += v1 = " << v2 << std::endl; v2 = v2 - v1; std::cout << "v2 -= v1 = " << v2 << std::endl; #endif v1 *= value_type (1.); std::cout << "v1 *= 1. = " << v1 << std::endl; v1 *= t; std::cout << "v1 *= N = " << v1 << std::endl; // Unary vector operations resulting in a scalar initialize_vector (v1); t = ublas::sum (v1); std::cout << "sum (v1) = " << t << std::endl; n = ublas::norm_1 (v1); std::cout << "norm_1 (v1) = " << n << std::endl; n = ublas::norm_2 (v1); std::cout << "norm_2 (v1) = " << n << std::endl; n = ublas::norm_inf (v1); std::cout << "norm_inf (v1) = " << n << std::endl; i = ublas::index_norm_inf (v1); std::cout << "index_norm_inf (v1) = " << i << std::endl; // Binary vector operations resulting in a scalar initialize_vector (v1); initialize_vector (v2); t = ublas::inner_prod (v1, v2); std::cout << "inner_prod (v1, v2) = " << t << std::endl; } catch (std::exception &e) { std::cout << e.what () << std::endl; } catch (...) { std::cout << "unknown exception" << std::endl; } }
void test_with (VP &v1, VP &v2, VP &v3) const { { value_type t; size_type i; real_type n; // Default Construct default_construct<VP>::test (); // Copy and swap initialize_vector (v1); initialize_vector (v2); v1 = v2; std::cout << "v1 = v2 = " << v1 << std::endl; v1.assign_temporary (v2); std::cout << "v1.assign_temporary (v2) = " << v1 << std::endl; v1.swap (v2); std::cout << "v1.swap (v2) = " << v1 << " " << v2 << std::endl; #ifndef BOOST_NO_FUNCTION_TEMPLATE_ORDERING // Project range and slice initialize_vector (v1); initialize_vector (v2); project (v1, ublas::range(0,1)) = project (v2, ublas::range(0,1)); project (v1, ublas::range(0,1)) = project (v2, ublas::slice(0,1,1)); project (v1, ublas::slice(2,-1,2)) = project (v2, ublas::slice(0,1,2)); project (v1, ublas::slice(2,-1,2)) = project (v2, ublas::range(0,2)); std::cout << "v1 = range/slice " << v1 << std::endl; #endif // Unary vector operations resulting in a vector initialize_vector (v1); v2 = - v1; std::cout << "- v1 = " << v2 << std::endl; v2 = ublas::conj (v1); std::cout << "conj (v1) = " << v2 << std::endl; // Binary vector operations resulting in a vector initialize_vector (v1); initialize_vector (v2); initialize_vector (v3); v3 = v1 + v2; std::cout << "v1 + v2 = " << v3 << std::endl; v3 = v1 - v2; std::cout << "v1 - v2 = " << v3 << std::endl; // Scaling a vector t = N; initialize_vector (v1); v2 = value_type (1.) * v1; std::cout << "1. * v1 = " << v2 << std::endl; v2 = t * v1; std::cout << "N * v1 = " << v2 << std::endl; initialize_vector (v1); v2 = v1 * value_type (1.); std::cout << "v1 * 1. = " << v2 << std::endl; v2 = v1 * t; std::cout << "v1 * N = " << v2 << std::endl; // Some assignments initialize_vector (v1); initialize_vector (v2); v2 += v1; std::cout << "v2 += v1 = " << v2 << std::endl; v2 -= v1; std::cout << "v2 -= v1 = " << v2 << std::endl; v2 = v2 + v1; std::cout << "v2 = v2 + v1 = " << v2 << std::endl; v2 = v2 - v1; std::cout << "v2 = v2 - v1 = " << v2 << std::endl; v1 *= value_type (1.); std::cout << "v1 *= 1. = " << v1 << std::endl; v1 *= t; std::cout << "v1 *= N = " << v1 << std::endl; // Unary vector operations resulting in a scalar initialize_vector (v1); t = ublas::sum (v1); std::cout << "sum (v1) = " << t << std::endl; n = ublas::norm_1 (v1); std::cout << "norm_1 (v1) = " << n << std::endl; n = ublas::norm_2 (v1); std::cout << "norm_2 (v1) = " << n << std::endl; n = ublas::norm_inf (v1); std::cout << "norm_inf (v1) = " << n << std::endl; i = ublas::index_norm_inf (v1); std::cout << "index_norm_inf (v1) = " << i << std::endl; // Binary vector operations resulting in a scalar initialize_vector (v1); initialize_vector (v2); t = ublas::inner_prod (v1, v2); std::cout << "inner_prod (v1, v2) = " << t << std::endl; } }