Alp?r javaslat?ra k?sz?tettem egy strukt?r?t 2 dimenzi?s vektorok (s?kvektorok) t?rol?s?ra. Olyasmiket tud, amiket s?kvektorokt?l szeretn?nk. A neve: xy, a hasonl? nevu .h file-ban tal?lhat?.
authorathos
Thu, 18 Mar 2004 16:50:07 +0000
changeset 201b9158a014fe8
parent 200 f40bb16b0405
child 202 0bd4fe53b1d0
Alp?r javaslat?ra k?sz?tettem egy strukt?r?t 2 dimenzi?s vektorok (s?kvektorok) t?rol?s?ra. Olyasmiket tud, amiket s?kvektorokt?l szeretn?nk. A neve: xy, a hasonl? nevu .h file-ban tal?lhat?.
src/work/athos/makefile
src/work/athos/pf_demo.cc
src/work/athos/xy/xy.cc
src/work/athos/xy/xy.h
     1.1 --- a/src/work/athos/makefile	Thu Mar 18 12:07:37 2004 +0000
     1.2 +++ b/src/work/athos/makefile	Thu Mar 18 16:50:07 2004 +0000
     1.3 @@ -1,7 +1,7 @@
     1.4  CXXFLAGS = -Wall -ansi -g
     1.5  CXX = g++-3.0
     1.6  
     1.7 -pf_demo: pf_demo.cc ../marci_graph_traits.hh ../marci_list_graph.hh ../marci_property_vector.hh preflow_push.hh ../reverse_bfs.hh
     1.8 +pf_demo: pf_demo.cc ../marci_graph_traits.hh ../list_graph.hh ../marci_property_vector.hh preflow_push.hh reverse_bfs.hh
     1.9  	$(CXX) $(CXXFLAGS) -I. -I.. pf_demo.cc -o pf_demo 
    1.10  
    1.11  
     2.1 --- a/src/work/athos/pf_demo.cc	Thu Mar 18 12:07:37 2004 +0000
     2.2 +++ b/src/work/athos/pf_demo.cc	Thu Mar 18 16:50:07 2004 +0000
     2.3 @@ -23,9 +23,11 @@
     2.4    typedef ListGraph::InEdgeIt InEdgeIt;
     2.5    typedef ListGraph::SymEdgeIt SymEdgeIt;
     2.6    */
     2.7 -  
     2.8 +  ListGraph flowG;
     2.9 +
    2.10 +  /*
    2.11    //Marci példája
    2.12 -  ListGraph flowG;
    2.13 +
    2.14  
    2.15    NodeIt s=flowG.addNode();
    2.16    NodeIt v1=flowG.addNode();
    2.17 @@ -58,62 +60,42 @@
    2.18    cap.set(v4_v3, 7);
    2.19    cap.set(v3_t, 20);
    2.20    cap.set(v4_t, 4);
    2.21 +  */
    2.22  
    2.23  
    2.24 +  //Ahuja könyv példája
    2.25  
    2.26 +  NodeIt s=flowG.addNode();
    2.27 +  NodeIt v2=flowG.addNode();
    2.28 +  NodeIt v3=flowG.addNode();
    2.29 +  NodeIt v4=flowG.addNode();
    2.30 +  NodeIt v5=flowG.addNode();
    2.31 +  NodeIt t=flowG.addNode();
    2.32  
    2.33 -
    2.34 -
    2.35 -
    2.36 -  /*
    2.37 -  //Ahuja könyv példája
    2.38 -  node_iterator s=flow_test.add_node();
    2.39 -  NodeIt v2=flow_test.add_node();
    2.40 -  NodeIt v3=flow_test.add_node();
    2.41 -  NodeIt v4=flow_test.add_node();
    2.42 -  NodeIt v5=flow_test.add_node();
    2.43 -  NodeIt t=flow_test.add_node();
    2.44 -  
    2.45 -  node_property_vector<list_graph, std::string> node_name(flow_test);
    2.46 -  node_name.put(s, "s");  
    2.47 -  node_name.put(v2, "v2");
    2.48 -  node_name.put(v3, "v3");
    2.49 -  node_name.put(v4, "v4");
    2.50 -  node_name.put(v5, "v5");
    2.51 -  node_name.put(t, "t");
    2.52 -
    2.53 -  
    2.54 -  edge_iterator s_v2=flow_test.add_edge(s, v2);
    2.55 -  edge_iterator s_v3=flow_test.add_edge(s, v3);
    2.56 -  
    2.57 -  edge_iterator v2_v4=flow_test.add_edge(v2, v4);
    2.58 -  edge_iterator v2_v5=flow_test.add_edge(v2, v5);
    2.59 -
    2.60 -  edge_iterator v3_v5=flow_test.add_edge(v3, v5);
    2.61 -
    2.62 -  edge_iterator v4_t=flow_test.add_edge(v4, t);
    2.63 -  edge_iterator v5_t=flow_test.add_edge(v5, t);
    2.64 +  EdgeIt s_v2=flowG.addEdge(s, v2);
    2.65 +  EdgeIt s_v3=flowG.addEdge(s, v3);
    2.66 +  EdgeIt v2_v4=flowG.addEdge(v2, v4);
    2.67 +  EdgeIt v2_v5=flowG.addEdge(v2, v5);
    2.68 +  EdgeIt v3_v5=flowG.addEdge(v3, v5);
    2.69 +  EdgeIt v4_t=flowG.addEdge(v4, t);
    2.70 +  EdgeIt v5_t=flowG.addEdge(v5, t);
    2.71    
    2.72    //Kis modositas
    2.73 -  edge_iterator v2_s=flow_test.add_edge(v2, s);
    2.74 +  //edge_iterator v2_s=flowG.add_edge(v2, s);
    2.75  
    2.76 -  edge_property_vector<list_graph, int> cap(flow_test);  
    2.77 -  cap.put(s_v2, 10);
    2.78 -  cap.put(s_v3, 10);
    2.79 -  cap.put(v2_v4, 5);
    2.80 -  cap.put(v2_v5, 8);
    2.81 -  cap.put(v3_v5, 5);
    2.82 -  cap.put(v4_t, 8);
    2.83 -  cap.put(v5_t, 8);
    2.84 +  ListGraph::EdgeMap<int> cap(flowG);
    2.85 +
    2.86 +  cap.set(s_v2, 10);
    2.87 +  cap.set(s_v3, 10);
    2.88 +  cap.set(v2_v4, 5);
    2.89 +  cap.set(v2_v5, 8);
    2.90 +  cap.set(v3_v5, 5);
    2.91 +  cap.set(v4_t, 8);
    2.92 +  cap.set(v5_t, 8);
    2.93  
    2.94    //Kis modositas
    2.95 -  cap.put(v2_s, 100);
    2.96 -
    2.97 -  //Kis modositas
    2.98 -  //edge_iterator t_s=flow_test.add_edge(t, s);
    2.99 -  //cap.put(t_s, 20);
   2.100 -
   2.101 -  */
   2.102 +  //cap.put(v2_s, 100);
   2.103 + 
   2.104  
   2.105  
   2.106  
     3.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     3.2 +++ b/src/work/athos/xy/xy.cc	Thu Mar 18 16:50:07 2004 +0000
     3.3 @@ -0,0 +1,26 @@
     3.4 +#include <xy.h>
     3.5 +#include <iostream>
     3.6 +using namespace std;
     3.7 +int main()
     3.8 +{
     3.9 +	cout << "Kerek sok sikvektorokat." << endl;
    3.10 +
    3.11 +	xy<int> osszeg;
    3.12 +	xy<int> z;
    3.13 +
    3.14 +	vector< xy<int> > v;
    3.15 +
    3.16 +	while(cin >> z) {
    3.17 +		v.push_back(z);
    3.18 +		osszeg += z;
    3.19 +       		cout << "Az összeg aktualisan: " << osszeg << endl;
    3.20 +	}
    3.21 +
    3.22 +
    3.23 +
    3.24 +	cout << "A kovetkezo szamokat szoroztam ossze:" << endl;
    3.25 +	for(unsigned int i=0; i<v.size(); ++i) {
    3.26 +	  cout << v[i] << ", A normanégyzete: " << v[i].normSquare() <<endl;
    3.27 +	}
    3.28 +	cout << "Eleg nehez volt." << endl;
    3.29 +}
     4.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     4.2 +++ b/src/work/athos/xy/xy.h	Thu Mar 18 16:50:07 2004 +0000
     4.3 @@ -0,0 +1,117 @@
     4.4 +/**
     4.5 +2 dimensional vector (plainvector) implementation
     4.6 +
     4.7 +*/
     4.8 +#ifndef HUGO_XY_H
     4.9 +#define HUGO_XY_H
    4.10 +
    4.11 +#include <iostream>
    4.12 +
    4.13 +using namespace std;
    4.14 +template<typename T>
    4.15 +class xy {
    4.16 +  T _x,_y;
    4.17 +
    4.18 +public:
    4.19 +
    4.20 +  ///Default constructor: both coordinates become 0
    4.21 +  xy() { _x=_y=0; }
    4.22 +
    4.23 +  ///Constructing from coordinates
    4.24 +  xy(T a, T b) { _x=a; _y=b; }
    4.25 +
    4.26 +  ///Gives back the x coordinate
    4.27 +  T x(){
    4.28 +    return _x;
    4.29 +  };
    4.30 +
    4.31 +  ///Gives back the y coordinate
    4.32 +  T y(){
    4.33 +    return _y;
    4.34 +  };
    4.35 +
    4.36 +  ///Gives back the square of the norm of the vector
    4.37 +  T normSquare(){
    4.38 +    return _x*_x+_y*_y;
    4.39 +  };
    4.40 +  
    4.41 +  ///Increments the left hand side by u
    4.42 +  xy<T>& operator +=(const xy<T>& u){
    4.43 +    _x += u._x;
    4.44 +    _y += u._y;
    4.45 +    return *this;
    4.46 +  };
    4.47 +  
    4.48 +  ///Decrements the left hand side by u
    4.49 +  xy<T>& operator -=(const xy<T>& u){
    4.50 +    _x -= u._x;
    4.51 +    _y -= u._y;
    4.52 +    return *this;
    4.53 +  };
    4.54 +
    4.55 +  ///Multiplying the left hand side with a scalar
    4.56 +  xy<T>& operator *=(const T &u){
    4.57 +    _x *= u;
    4.58 +    _y *= u;
    4.59 +    return *this;
    4.60 +  };
    4.61 +  
    4.62 +  ///Returns the scalar product of two vectors
    4.63 +  T operator *(const xy<T>& u){
    4.64 +    return _x*u._x+_y*u._y;
    4.65 +  };
    4.66 +  
    4.67 +  ///Returns the sum of two vectors
    4.68 +  xy<T> operator+(const xy<T> &u) const {
    4.69 +    xy<T> b=*this;
    4.70 +    return b+=u;
    4.71 +  };
    4.72 +
    4.73 +  ///Returns the difference of two vectors
    4.74 +  xy<T> operator-(const xy<T> &u) const {
    4.75 +    xy<T> b=*this;
    4.76 +    return b-=u;
    4.77 +  };
    4.78 +
    4.79 +  ///Returns a vector multiplied by a scalar
    4.80 +  xy<T> operator*(const T &u) const {
    4.81 +    xy<T> b=*this;
    4.82 +    return b*=u;
    4.83 +  };
    4.84 +
    4.85 +  ///Testing equality
    4.86 +  bool operator==(const xy<T> &u){
    4.87 +    return (_x==u._x) && (_y==u._y);
    4.88 +  };
    4.89 +
    4.90 +  ///Testing inequality
    4.91 +  bool operator!=(xy u){
    4.92 +    return  (_x!=u._x) || (_y!=u._y);
    4.93 +  };
    4.94 +
    4.95 +};
    4.96 +///Reading a plainvector from a stream
    4.97 +template<typename T>
    4.98 +inline
    4.99 +istream& operator>>(istream &is, xy<T> &z)
   4.100 +{
   4.101 +  ///This is not the best solution here: I didn't know how to solve this with friend functions
   4.102 +  T a,b;
   4.103 +  is >> a >> b;
   4.104 +  xy<T> buf(a,b);
   4.105 +  z=buf;
   4.106 +  return is;
   4.107 +}
   4.108 +
   4.109 +///Outputting a plainvector to a stream
   4.110 +template<typename T>
   4.111 +inline
   4.112 +ostream& operator<<(ostream &os, xy<T> z)
   4.113 +{
   4.114 +	os << "(" << z.x() << ", " << z.y() << ")";
   4.115 +	return os;
   4.116 +}
   4.117 +
   4.118 +
   4.119 +
   4.120 +#endif //HUGO_XY_H