examples/matrix-topology/matrix-topology.cc
author Lalith Suresh <suresh.lalith@gmail.com>
Thu, 03 Mar 2011 19:54:57 +0000
changeset 6848 1f453ad50ef3
parent 6847 138f00c56381
child 6865 220373544a6c
permissions -rw-r--r--
Converts csma, emu, tap-bridge, point-to-point, wifi and wimax modules into modular format
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
6627
b6a64626353c Matrix topology example program
Egemen K. Cetinkaya <ekc@ittc.ku.edu>
parents:
diff changeset
     1
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
b6a64626353c Matrix topology example program
Egemen K. Cetinkaya <ekc@ittc.ku.edu>
parents:
diff changeset
     2
/*
b6a64626353c Matrix topology example program
Egemen K. Cetinkaya <ekc@ittc.ku.edu>
parents:
diff changeset
     3
 * Copyright (c) 2010 Egemen K. Cetinkaya, Justin P. Rohrer, and Amit Dandekar
b6a64626353c Matrix topology example program
Egemen K. Cetinkaya <ekc@ittc.ku.edu>
parents:
diff changeset
     4
 *
b6a64626353c Matrix topology example program
Egemen K. Cetinkaya <ekc@ittc.ku.edu>
parents:
diff changeset
     5
 * This program is free software; you can redistribute it and/or modify
b6a64626353c Matrix topology example program
Egemen K. Cetinkaya <ekc@ittc.ku.edu>
parents:
diff changeset
     6
 * it under the terms of the GNU General Public License version 2 as
b6a64626353c Matrix topology example program
Egemen K. Cetinkaya <ekc@ittc.ku.edu>
parents:
diff changeset
     7
 * published by the Free Software Foundation;
b6a64626353c Matrix topology example program
Egemen K. Cetinkaya <ekc@ittc.ku.edu>
parents:
diff changeset
     8
 *
b6a64626353c Matrix topology example program
Egemen K. Cetinkaya <ekc@ittc.ku.edu>
parents:
diff changeset
     9
 * This program is distributed in the hope that it will be useful,
b6a64626353c Matrix topology example program
Egemen K. Cetinkaya <ekc@ittc.ku.edu>
parents:
diff changeset
    10
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
b6a64626353c Matrix topology example program
Egemen K. Cetinkaya <ekc@ittc.ku.edu>
parents:
diff changeset
    11
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
b6a64626353c Matrix topology example program
Egemen K. Cetinkaya <ekc@ittc.ku.edu>
parents:
diff changeset
    12
 * GNU General Public License for more details.
b6a64626353c Matrix topology example program
Egemen K. Cetinkaya <ekc@ittc.ku.edu>
parents:
diff changeset
    13
 *
b6a64626353c Matrix topology example program
Egemen K. Cetinkaya <ekc@ittc.ku.edu>
parents:
diff changeset
    14
 * You should have received a copy of the GNU General Public License
b6a64626353c Matrix topology example program
Egemen K. Cetinkaya <ekc@ittc.ku.edu>
parents:
diff changeset
    15
 * along with this program; if not, write to the Free Software
b6a64626353c Matrix topology example program
Egemen K. Cetinkaya <ekc@ittc.ku.edu>
parents:
diff changeset
    16
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
b6a64626353c Matrix topology example program
Egemen K. Cetinkaya <ekc@ittc.ku.edu>
parents:
diff changeset
    17
 *
b6a64626353c Matrix topology example program
Egemen K. Cetinkaya <ekc@ittc.ku.edu>
parents:
diff changeset
    18
 * Author: Egemen K. Cetinkaya <ekc@ittc.ku.edu>
6629
b4d07d7badad Fix comments on matrix-topology example
Egemen K. Cetinkaya <ekc@ittc.ku.edu>
parents: 6628
diff changeset
    19
 * Author: Justin P. Rohrer    <rohrej@ittc.ku.edu>
6627
b6a64626353c Matrix topology example program
Egemen K. Cetinkaya <ekc@ittc.ku.edu>
parents:
diff changeset
    20
 * Author: Amit Dandekar       <dandekar@ittc.ku.edu>
b6a64626353c Matrix topology example program
Egemen K. Cetinkaya <ekc@ittc.ku.edu>
parents:
diff changeset
    21
 *
6629
b4d07d7badad Fix comments on matrix-topology example
Egemen K. Cetinkaya <ekc@ittc.ku.edu>
parents: 6628
diff changeset
    22
 * James P.G. Sterbenz <jpgs@ittc.ku.edu>, director
b4d07d7badad Fix comments on matrix-topology example
Egemen K. Cetinkaya <ekc@ittc.ku.edu>
parents: 6628
diff changeset
    23
 * ResiliNets Research Group  http://wiki.ittc.ku.edu/resilinets
b4d07d7badad Fix comments on matrix-topology example
Egemen K. Cetinkaya <ekc@ittc.ku.edu>
parents: 6628
diff changeset
    24
 * Information and Telecommunication Technology Center 
b4d07d7badad Fix comments on matrix-topology example
Egemen K. Cetinkaya <ekc@ittc.ku.edu>
parents: 6628
diff changeset
    25
 * and
b4d07d7badad Fix comments on matrix-topology example
Egemen K. Cetinkaya <ekc@ittc.ku.edu>
parents: 6628
diff changeset
    26
 * Department of Electrical Engineering and Computer Science
b4d07d7badad Fix comments on matrix-topology example
Egemen K. Cetinkaya <ekc@ittc.ku.edu>
parents: 6628
diff changeset
    27
 * The University of Kansas
b4d07d7badad Fix comments on matrix-topology example
Egemen K. Cetinkaya <ekc@ittc.ku.edu>
parents: 6628
diff changeset
    28
 * Lawrence, KS  USA
b4d07d7badad Fix comments on matrix-topology example
Egemen K. Cetinkaya <ekc@ittc.ku.edu>
parents: 6628
diff changeset
    29
 *
b4d07d7badad Fix comments on matrix-topology example
Egemen K. Cetinkaya <ekc@ittc.ku.edu>
parents: 6628
diff changeset
    30
 * Work supported in part by NSF FIND (Future Internet Design) Program
b4d07d7badad Fix comments on matrix-topology example
Egemen K. Cetinkaya <ekc@ittc.ku.edu>
parents: 6628
diff changeset
    31
 * under grant CNS-0626918 (Postmodern Internet Architecture) and 
b4d07d7badad Fix comments on matrix-topology example
Egemen K. Cetinkaya <ekc@ittc.ku.edu>
parents: 6628
diff changeset
    32
 * by NSF grant CNS-1050226 (Multilayer Network Resilience Analysis and Experimentation on GENI)
6627
b6a64626353c Matrix topology example program
Egemen K. Cetinkaya <ekc@ittc.ku.edu>
parents:
diff changeset
    33
 *
b6a64626353c Matrix topology example program
Egemen K. Cetinkaya <ekc@ittc.ku.edu>
parents:
diff changeset
    34
 * This program reads an upper triangular adjacency matrix (e.g. adjacency_matrix.txt) and
b6a64626353c Matrix topology example program
Egemen K. Cetinkaya <ekc@ittc.ku.edu>
parents:
diff changeset
    35
 * node coordinates file (e.g. node_coordinates.txt). The program also set-ups a
b6a64626353c Matrix topology example program
Egemen K. Cetinkaya <ekc@ittc.ku.edu>
parents:
diff changeset
    36
 * wired network topology with P2P links according to the adjacency matrix with
b6a64626353c Matrix topology example program
Egemen K. Cetinkaya <ekc@ittc.ku.edu>
parents:
diff changeset
    37
 * nx(n-1) CBR traffic flows, in which n is the number of nodes in the adjacency matrix.
b6a64626353c Matrix topology example program
Egemen K. Cetinkaya <ekc@ittc.ku.edu>
parents:
diff changeset
    38
 */
b6a64626353c Matrix topology example program
Egemen K. Cetinkaya <ekc@ittc.ku.edu>
parents:
diff changeset
    39
b6a64626353c Matrix topology example program
Egemen K. Cetinkaya <ekc@ittc.ku.edu>
parents:
diff changeset
    40
// ---------- Header Includes -------------------------------------------------
b6a64626353c Matrix topology example program
Egemen K. Cetinkaya <ekc@ittc.ku.edu>
parents:
diff changeset
    41
#include <iostream>
b6a64626353c Matrix topology example program
Egemen K. Cetinkaya <ekc@ittc.ku.edu>
parents:
diff changeset
    42
#include <fstream>
b6a64626353c Matrix topology example program
Egemen K. Cetinkaya <ekc@ittc.ku.edu>
parents:
diff changeset
    43
#include <sstream>
b6a64626353c Matrix topology example program
Egemen K. Cetinkaya <ekc@ittc.ku.edu>
parents:
diff changeset
    44
#include <string>
b6a64626353c Matrix topology example program
Egemen K. Cetinkaya <ekc@ittc.ku.edu>
parents:
diff changeset
    45
#include <vector>
b6a64626353c Matrix topology example program
Egemen K. Cetinkaya <ekc@ittc.ku.edu>
parents:
diff changeset
    46
#include <cstdlib>
b6a64626353c Matrix topology example program
Egemen K. Cetinkaya <ekc@ittc.ku.edu>
parents:
diff changeset
    47
#include <time.h>
b6a64626353c Matrix topology example program
Egemen K. Cetinkaya <ekc@ittc.ku.edu>
parents:
diff changeset
    48
b6a64626353c Matrix topology example program
Egemen K. Cetinkaya <ekc@ittc.ku.edu>
parents:
diff changeset
    49
#include "ns3/core-module.h"
6823
a27f86fb4e55 Merge node and common modules into new network module
Tom Henderson <tomh@tomh.org>
parents: 6821
diff changeset
    50
#include "ns3/network-module.h"
6848
1f453ad50ef3 Converts csma, emu, tap-bridge, point-to-point, wifi and wimax modules into modular format
Lalith Suresh <suresh.lalith@gmail.com>
parents: 6847
diff changeset
    51
#include "ns3/internet-module.h"
1f453ad50ef3 Converts csma, emu, tap-bridge, point-to-point, wifi and wimax modules into modular format
Lalith Suresh <suresh.lalith@gmail.com>
parents: 6847
diff changeset
    52
#include "ns3/point-to-point-module.h"
6627
b6a64626353c Matrix topology example program
Egemen K. Cetinkaya <ekc@ittc.ku.edu>
parents:
diff changeset
    53
#include "ns3/helper-module.h"
6847
138f00c56381 Move applications to a single module
Mitch Watrous <watrous@u.washington.edu>
parents: 6845
diff changeset
    54
#include "ns3/applications-module.h"
6627
b6a64626353c Matrix topology example program
Egemen K. Cetinkaya <ekc@ittc.ku.edu>
parents:
diff changeset
    55
#include "ns3/global-route-manager.h"
b6a64626353c Matrix topology example program
Egemen K. Cetinkaya <ekc@ittc.ku.edu>
parents:
diff changeset
    56
#include "ns3/mobility-module.h"
b6a64626353c Matrix topology example program
Egemen K. Cetinkaya <ekc@ittc.ku.edu>
parents:
diff changeset
    57
#include "ns3/assert.h"
6649
f5413d463948 Missing ipv4-global-routing-helper.h include
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6629
diff changeset
    58
#include "ns3/ipv4-global-routing-helper.h"
6627
b6a64626353c Matrix topology example program
Egemen K. Cetinkaya <ekc@ittc.ku.edu>
parents:
diff changeset
    59
b6a64626353c Matrix topology example program
Egemen K. Cetinkaya <ekc@ittc.ku.edu>
parents:
diff changeset
    60
using namespace std;
b6a64626353c Matrix topology example program
Egemen K. Cetinkaya <ekc@ittc.ku.edu>
parents:
diff changeset
    61
using namespace ns3;
b6a64626353c Matrix topology example program
Egemen K. Cetinkaya <ekc@ittc.ku.edu>
parents:
diff changeset
    62
b6a64626353c Matrix topology example program
Egemen K. Cetinkaya <ekc@ittc.ku.edu>
parents:
diff changeset
    63
// ---------- Prototypes ------------------------------------------------------
b6a64626353c Matrix topology example program
Egemen K. Cetinkaya <ekc@ittc.ku.edu>
parents:
diff changeset
    64
b6a64626353c Matrix topology example program
Egemen K. Cetinkaya <ekc@ittc.ku.edu>
parents:
diff changeset
    65
vector<vector<bool> > readNxNMatrix (std::string adj_mat_file_name);
b6a64626353c Matrix topology example program
Egemen K. Cetinkaya <ekc@ittc.ku.edu>
parents:
diff changeset
    66
vector<vector<double> > readCordinatesFile (std::string node_coordinates_file_name);
b6a64626353c Matrix topology example program
Egemen K. Cetinkaya <ekc@ittc.ku.edu>
parents:
diff changeset
    67
void printCoordinateArray (const char* description, vector<vector<double> > coord_array);
b6a64626353c Matrix topology example program
Egemen K. Cetinkaya <ekc@ittc.ku.edu>
parents:
diff changeset
    68
void printMatrix (const char* description, vector<vector<bool> > array);
b6a64626353c Matrix topology example program
Egemen K. Cetinkaya <ekc@ittc.ku.edu>
parents:
diff changeset
    69
b6a64626353c Matrix topology example program
Egemen K. Cetinkaya <ekc@ittc.ku.edu>
parents:
diff changeset
    70
NS_LOG_COMPONENT_DEFINE ("GenericTopologyCreation");
b6a64626353c Matrix topology example program
Egemen K. Cetinkaya <ekc@ittc.ku.edu>
parents:
diff changeset
    71
b6a64626353c Matrix topology example program
Egemen K. Cetinkaya <ekc@ittc.ku.edu>
parents:
diff changeset
    72
int main (int argc, char *argv[])
b6a64626353c Matrix topology example program
Egemen K. Cetinkaya <ekc@ittc.ku.edu>
parents:
diff changeset
    73
{
b6a64626353c Matrix topology example program
Egemen K. Cetinkaya <ekc@ittc.ku.edu>
parents:
diff changeset
    74
b6a64626353c Matrix topology example program
Egemen K. Cetinkaya <ekc@ittc.ku.edu>
parents:
diff changeset
    75
  // ---------- Simulation Variables ------------------------------------------
b6a64626353c Matrix topology example program
Egemen K. Cetinkaya <ekc@ittc.ku.edu>
parents:
diff changeset
    76
b6a64626353c Matrix topology example program
Egemen K. Cetinkaya <ekc@ittc.ku.edu>
parents:
diff changeset
    77
  // Change the variables and file names only in this block!
b6a64626353c Matrix topology example program
Egemen K. Cetinkaya <ekc@ittc.ku.edu>
parents:
diff changeset
    78
b6a64626353c Matrix topology example program
Egemen K. Cetinkaya <ekc@ittc.ku.edu>
parents:
diff changeset
    79
  double SimTime        = 3.00;
b6a64626353c Matrix topology example program
Egemen K. Cetinkaya <ekc@ittc.ku.edu>
parents:
diff changeset
    80
  double SinkStartTime  = 1.0001;
b6a64626353c Matrix topology example program
Egemen K. Cetinkaya <ekc@ittc.ku.edu>
parents:
diff changeset
    81
  double SinkStopTime   = 2.90001;
b6a64626353c Matrix topology example program
Egemen K. Cetinkaya <ekc@ittc.ku.edu>
parents:
diff changeset
    82
  double AppStartTime   = 2.0001;
b6a64626353c Matrix topology example program
Egemen K. Cetinkaya <ekc@ittc.ku.edu>
parents:
diff changeset
    83
  double AppStopTime    = 2.80001;
b6a64626353c Matrix topology example program
Egemen K. Cetinkaya <ekc@ittc.ku.edu>
parents:
diff changeset
    84
b6a64626353c Matrix topology example program
Egemen K. Cetinkaya <ekc@ittc.ku.edu>
parents:
diff changeset
    85
  std::string AppPacketRate ("40Kbps");
b6a64626353c Matrix topology example program
Egemen K. Cetinkaya <ekc@ittc.ku.edu>
parents:
diff changeset
    86
  Config::SetDefault  ("ns3::OnOffApplication::PacketSize",StringValue ("1000"));
b6a64626353c Matrix topology example program
Egemen K. Cetinkaya <ekc@ittc.ku.edu>
parents:
diff changeset
    87
  Config::SetDefault ("ns3::OnOffApplication::DataRate",  StringValue (AppPacketRate));
b6a64626353c Matrix topology example program
Egemen K. Cetinkaya <ekc@ittc.ku.edu>
parents:
diff changeset
    88
  std::string LinkRate ("10Mbps");
b6a64626353c Matrix topology example program
Egemen K. Cetinkaya <ekc@ittc.ku.edu>
parents:
diff changeset
    89
  std::string LinkDelay ("2ms");
b6a64626353c Matrix topology example program
Egemen K. Cetinkaya <ekc@ittc.ku.edu>
parents:
diff changeset
    90
  //  DropTailQueue::MaxPackets affects the # of dropped packets, default value:100
b6a64626353c Matrix topology example program
Egemen K. Cetinkaya <ekc@ittc.ku.edu>
parents:
diff changeset
    91
  //  Config::SetDefault ("ns3::DropTailQueue::MaxPackets", UintegerValue (1000));
b6a64626353c Matrix topology example program
Egemen K. Cetinkaya <ekc@ittc.ku.edu>
parents:
diff changeset
    92
b6a64626353c Matrix topology example program
Egemen K. Cetinkaya <ekc@ittc.ku.edu>
parents:
diff changeset
    93
  srand ( (unsigned)time ( NULL ) );   // generate different seed each time
b6a64626353c Matrix topology example program
Egemen K. Cetinkaya <ekc@ittc.ku.edu>
parents:
diff changeset
    94
b6a64626353c Matrix topology example program
Egemen K. Cetinkaya <ekc@ittc.ku.edu>
parents:
diff changeset
    95
  std::string tr_name ("n-node-ppp.tr");
b6a64626353c Matrix topology example program
Egemen K. Cetinkaya <ekc@ittc.ku.edu>
parents:
diff changeset
    96
  std::string pcap_name ("n-node-ppp");
b6a64626353c Matrix topology example program
Egemen K. Cetinkaya <ekc@ittc.ku.edu>
parents:
diff changeset
    97
  std::string flow_name ("n-node-ppp.xml");
b6a64626353c Matrix topology example program
Egemen K. Cetinkaya <ekc@ittc.ku.edu>
parents:
diff changeset
    98
  std::string anim_name ("n-node-ppp.anim");
b6a64626353c Matrix topology example program
Egemen K. Cetinkaya <ekc@ittc.ku.edu>
parents:
diff changeset
    99
b6a64626353c Matrix topology example program
Egemen K. Cetinkaya <ekc@ittc.ku.edu>
parents:
diff changeset
   100
  std::string adj_mat_file_name ("examples/matrix-topology/adjacency_matrix.txt");
b6a64626353c Matrix topology example program
Egemen K. Cetinkaya <ekc@ittc.ku.edu>
parents:
diff changeset
   101
  std::string node_coordinates_file_name ("examples/matrix-topology/node_coordinates.txt");
b6a64626353c Matrix topology example program
Egemen K. Cetinkaya <ekc@ittc.ku.edu>
parents:
diff changeset
   102
b6a64626353c Matrix topology example program
Egemen K. Cetinkaya <ekc@ittc.ku.edu>
parents:
diff changeset
   103
  // ---------- End of Simulation Variables ----------------------------------
b6a64626353c Matrix topology example program
Egemen K. Cetinkaya <ekc@ittc.ku.edu>
parents:
diff changeset
   104
b6a64626353c Matrix topology example program
Egemen K. Cetinkaya <ekc@ittc.ku.edu>
parents:
diff changeset
   105
  // ---------- Read Adjacency Matrix ----------------------------------------
b6a64626353c Matrix topology example program
Egemen K. Cetinkaya <ekc@ittc.ku.edu>
parents:
diff changeset
   106
b6a64626353c Matrix topology example program
Egemen K. Cetinkaya <ekc@ittc.ku.edu>
parents:
diff changeset
   107
  vector<vector<bool> > Adj_Matrix;
b6a64626353c Matrix topology example program
Egemen K. Cetinkaya <ekc@ittc.ku.edu>
parents:
diff changeset
   108
  Adj_Matrix = readNxNMatrix (adj_mat_file_name);
b6a64626353c Matrix topology example program
Egemen K. Cetinkaya <ekc@ittc.ku.edu>
parents:
diff changeset
   109
b6a64626353c Matrix topology example program
Egemen K. Cetinkaya <ekc@ittc.ku.edu>
parents:
diff changeset
   110
  // Optionally display 2-dimensional adjacency matrix (Adj_Matrix) array
b6a64626353c Matrix topology example program
Egemen K. Cetinkaya <ekc@ittc.ku.edu>
parents:
diff changeset
   111
  // printMatrix (adj_mat_file_name.c_str (),Adj_Matrix);
b6a64626353c Matrix topology example program
Egemen K. Cetinkaya <ekc@ittc.ku.edu>
parents:
diff changeset
   112
b6a64626353c Matrix topology example program
Egemen K. Cetinkaya <ekc@ittc.ku.edu>
parents:
diff changeset
   113
  // ---------- End of Read Adjacency Matrix ---------------------------------
b6a64626353c Matrix topology example program
Egemen K. Cetinkaya <ekc@ittc.ku.edu>
parents:
diff changeset
   114
b6a64626353c Matrix topology example program
Egemen K. Cetinkaya <ekc@ittc.ku.edu>
parents:
diff changeset
   115
  // ---------- Read Node Coordinates File -----------------------------------
b6a64626353c Matrix topology example program
Egemen K. Cetinkaya <ekc@ittc.ku.edu>
parents:
diff changeset
   116
b6a64626353c Matrix topology example program
Egemen K. Cetinkaya <ekc@ittc.ku.edu>
parents:
diff changeset
   117
  vector<vector<double> > coord_array;
b6a64626353c Matrix topology example program
Egemen K. Cetinkaya <ekc@ittc.ku.edu>
parents:
diff changeset
   118
  coord_array = readCordinatesFile (node_coordinates_file_name);
b6a64626353c Matrix topology example program
Egemen K. Cetinkaya <ekc@ittc.ku.edu>
parents:
diff changeset
   119
b6a64626353c Matrix topology example program
Egemen K. Cetinkaya <ekc@ittc.ku.edu>
parents:
diff changeset
   120
  // Optionally display node co-ordinates file
b6a64626353c Matrix topology example program
Egemen K. Cetinkaya <ekc@ittc.ku.edu>
parents:
diff changeset
   121
  // printCoordinateArray (node_coordinates_file_name.c_str (),coord_array);
b6a64626353c Matrix topology example program
Egemen K. Cetinkaya <ekc@ittc.ku.edu>
parents:
diff changeset
   122
b6a64626353c Matrix topology example program
Egemen K. Cetinkaya <ekc@ittc.ku.edu>
parents:
diff changeset
   123
  int n_nodes = coord_array.size ();
b6a64626353c Matrix topology example program
Egemen K. Cetinkaya <ekc@ittc.ku.edu>
parents:
diff changeset
   124
  int matrixDimension = Adj_Matrix.size ();
b6a64626353c Matrix topology example program
Egemen K. Cetinkaya <ekc@ittc.ku.edu>
parents:
diff changeset
   125
b6a64626353c Matrix topology example program
Egemen K. Cetinkaya <ekc@ittc.ku.edu>
parents:
diff changeset
   126
  if (matrixDimension != n_nodes)
b6a64626353c Matrix topology example program
Egemen K. Cetinkaya <ekc@ittc.ku.edu>
parents:
diff changeset
   127
    {
b6a64626353c Matrix topology example program
Egemen K. Cetinkaya <ekc@ittc.ku.edu>
parents:
diff changeset
   128
      NS_FATAL_ERROR ("The number of lines in coordinate file is: " << n_nodes << " not equal to the number of nodes in adjacency matrix size " << matrixDimension);
b6a64626353c Matrix topology example program
Egemen K. Cetinkaya <ekc@ittc.ku.edu>
parents:
diff changeset
   129
    }
b6a64626353c Matrix topology example program
Egemen K. Cetinkaya <ekc@ittc.ku.edu>
parents:
diff changeset
   130
b6a64626353c Matrix topology example program
Egemen K. Cetinkaya <ekc@ittc.ku.edu>
parents:
diff changeset
   131
  // ---------- End of Read Node Coordinates File ----------------------------
b6a64626353c Matrix topology example program
Egemen K. Cetinkaya <ekc@ittc.ku.edu>
parents:
diff changeset
   132
b6a64626353c Matrix topology example program
Egemen K. Cetinkaya <ekc@ittc.ku.edu>
parents:
diff changeset
   133
  // ---------- Network Setup ------------------------------------------------
b6a64626353c Matrix topology example program
Egemen K. Cetinkaya <ekc@ittc.ku.edu>
parents:
diff changeset
   134
b6a64626353c Matrix topology example program
Egemen K. Cetinkaya <ekc@ittc.ku.edu>
parents:
diff changeset
   135
  NS_LOG_INFO ("Create Nodes.");
b6a64626353c Matrix topology example program
Egemen K. Cetinkaya <ekc@ittc.ku.edu>
parents:
diff changeset
   136
b6a64626353c Matrix topology example program
Egemen K. Cetinkaya <ekc@ittc.ku.edu>
parents:
diff changeset
   137
  NodeContainer nodes;   // Declare nodes objects
b6a64626353c Matrix topology example program
Egemen K. Cetinkaya <ekc@ittc.ku.edu>
parents:
diff changeset
   138
  nodes.Create (n_nodes);
b6a64626353c Matrix topology example program
Egemen K. Cetinkaya <ekc@ittc.ku.edu>
parents:
diff changeset
   139
b6a64626353c Matrix topology example program
Egemen K. Cetinkaya <ekc@ittc.ku.edu>
parents:
diff changeset
   140
  NS_LOG_INFO ("Create P2P Link Attributes.");
b6a64626353c Matrix topology example program
Egemen K. Cetinkaya <ekc@ittc.ku.edu>
parents:
diff changeset
   141
b6a64626353c Matrix topology example program
Egemen K. Cetinkaya <ekc@ittc.ku.edu>
parents:
diff changeset
   142
  PointToPointHelper p2p;
b6a64626353c Matrix topology example program
Egemen K. Cetinkaya <ekc@ittc.ku.edu>
parents:
diff changeset
   143
  p2p.SetDeviceAttribute ("DataRate", StringValue (LinkRate));
b6a64626353c Matrix topology example program
Egemen K. Cetinkaya <ekc@ittc.ku.edu>
parents:
diff changeset
   144
  p2p.SetChannelAttribute ("Delay", StringValue (LinkDelay));
b6a64626353c Matrix topology example program
Egemen K. Cetinkaya <ekc@ittc.ku.edu>
parents:
diff changeset
   145
b6a64626353c Matrix topology example program
Egemen K. Cetinkaya <ekc@ittc.ku.edu>
parents:
diff changeset
   146
  NS_LOG_INFO ("Install Internet Stack to Nodes.");
b6a64626353c Matrix topology example program
Egemen K. Cetinkaya <ekc@ittc.ku.edu>
parents:
diff changeset
   147
b6a64626353c Matrix topology example program
Egemen K. Cetinkaya <ekc@ittc.ku.edu>
parents:
diff changeset
   148
  InternetStackHelper internet;
b6a64626353c Matrix topology example program
Egemen K. Cetinkaya <ekc@ittc.ku.edu>
parents:
diff changeset
   149
  internet.Install (NodeContainer::GetGlobal ());
b6a64626353c Matrix topology example program
Egemen K. Cetinkaya <ekc@ittc.ku.edu>
parents:
diff changeset
   150
b6a64626353c Matrix topology example program
Egemen K. Cetinkaya <ekc@ittc.ku.edu>
parents:
diff changeset
   151
  NS_LOG_INFO ("Assign Addresses to Nodes.");
b6a64626353c Matrix topology example program
Egemen K. Cetinkaya <ekc@ittc.ku.edu>
parents:
diff changeset
   152
b6a64626353c Matrix topology example program
Egemen K. Cetinkaya <ekc@ittc.ku.edu>
parents:
diff changeset
   153
  Ipv4AddressHelper ipv4_n;
b6a64626353c Matrix topology example program
Egemen K. Cetinkaya <ekc@ittc.ku.edu>
parents:
diff changeset
   154
  ipv4_n.SetBase ("10.0.0.0", "255.255.255.252");
b6a64626353c Matrix topology example program
Egemen K. Cetinkaya <ekc@ittc.ku.edu>
parents:
diff changeset
   155
b6a64626353c Matrix topology example program
Egemen K. Cetinkaya <ekc@ittc.ku.edu>
parents:
diff changeset
   156
  NS_LOG_INFO ("Create Links Between Nodes.");
b6a64626353c Matrix topology example program
Egemen K. Cetinkaya <ekc@ittc.ku.edu>
parents:
diff changeset
   157
b6a64626353c Matrix topology example program
Egemen K. Cetinkaya <ekc@ittc.ku.edu>
parents:
diff changeset
   158
  uint32_t linkCount = 0;
b6a64626353c Matrix topology example program
Egemen K. Cetinkaya <ekc@ittc.ku.edu>
parents:
diff changeset
   159
b6a64626353c Matrix topology example program
Egemen K. Cetinkaya <ekc@ittc.ku.edu>
parents:
diff changeset
   160
  for (size_t i = 0; i < Adj_Matrix.size (); i++)
b6a64626353c Matrix topology example program
Egemen K. Cetinkaya <ekc@ittc.ku.edu>
parents:
diff changeset
   161
    {
b6a64626353c Matrix topology example program
Egemen K. Cetinkaya <ekc@ittc.ku.edu>
parents:
diff changeset
   162
      for (size_t j = 0; j < Adj_Matrix[i].size (); j++)
b6a64626353c Matrix topology example program
Egemen K. Cetinkaya <ekc@ittc.ku.edu>
parents:
diff changeset
   163
        {
b6a64626353c Matrix topology example program
Egemen K. Cetinkaya <ekc@ittc.ku.edu>
parents:
diff changeset
   164
b6a64626353c Matrix topology example program
Egemen K. Cetinkaya <ekc@ittc.ku.edu>
parents:
diff changeset
   165
          if (Adj_Matrix[i][j] == 1)
b6a64626353c Matrix topology example program
Egemen K. Cetinkaya <ekc@ittc.ku.edu>
parents:
diff changeset
   166
            {
b6a64626353c Matrix topology example program
Egemen K. Cetinkaya <ekc@ittc.ku.edu>
parents:
diff changeset
   167
              NodeContainer n_links = NodeContainer (nodes.Get (i), nodes.Get (j));
b6a64626353c Matrix topology example program
Egemen K. Cetinkaya <ekc@ittc.ku.edu>
parents:
diff changeset
   168
              NetDeviceContainer n_devs = p2p.Install (n_links);
6659
f2e0d07fea48 remove unneeded array
Egemen K. Cetinkaya <ekc@ittc.ku.edu>
parents: 6649
diff changeset
   169
              ipv4_n.Assign (n_devs);
6627
b6a64626353c Matrix topology example program
Egemen K. Cetinkaya <ekc@ittc.ku.edu>
parents:
diff changeset
   170
              ipv4_n.NewNetwork ();
b6a64626353c Matrix topology example program
Egemen K. Cetinkaya <ekc@ittc.ku.edu>
parents:
diff changeset
   171
              linkCount++;
b6a64626353c Matrix topology example program
Egemen K. Cetinkaya <ekc@ittc.ku.edu>
parents:
diff changeset
   172
              NS_LOG_INFO ("matrix element [" << i << "][" << j << "] is 1");
b6a64626353c Matrix topology example program
Egemen K. Cetinkaya <ekc@ittc.ku.edu>
parents:
diff changeset
   173
            }
b6a64626353c Matrix topology example program
Egemen K. Cetinkaya <ekc@ittc.ku.edu>
parents:
diff changeset
   174
          else
b6a64626353c Matrix topology example program
Egemen K. Cetinkaya <ekc@ittc.ku.edu>
parents:
diff changeset
   175
            {
b6a64626353c Matrix topology example program
Egemen K. Cetinkaya <ekc@ittc.ku.edu>
parents:
diff changeset
   176
              NS_LOG_INFO ("matrix element [" << i << "][" << j << "] is 0");
b6a64626353c Matrix topology example program
Egemen K. Cetinkaya <ekc@ittc.ku.edu>
parents:
diff changeset
   177
            }
b6a64626353c Matrix topology example program
Egemen K. Cetinkaya <ekc@ittc.ku.edu>
parents:
diff changeset
   178
        }
b6a64626353c Matrix topology example program
Egemen K. Cetinkaya <ekc@ittc.ku.edu>
parents:
diff changeset
   179
    }
b6a64626353c Matrix topology example program
Egemen K. Cetinkaya <ekc@ittc.ku.edu>
parents:
diff changeset
   180
  NS_LOG_INFO ("Number of links in the adjacency matrix is: " << linkCount);
6628
0586bc1a18ce fix optimized build
Tom Henderson <tomh@tomh.org>
parents: 6627
diff changeset
   181
  NS_LOG_INFO ("Number of all nodes is: " << nodes.GetN ());
6627
b6a64626353c Matrix topology example program
Egemen K. Cetinkaya <ekc@ittc.ku.edu>
parents:
diff changeset
   182
b6a64626353c Matrix topology example program
Egemen K. Cetinkaya <ekc@ittc.ku.edu>
parents:
diff changeset
   183
  NS_LOG_INFO ("Initialize Global Routing.");
b6a64626353c Matrix topology example program
Egemen K. Cetinkaya <ekc@ittc.ku.edu>
parents:
diff changeset
   184
  Ipv4GlobalRoutingHelper::PopulateRoutingTables ();
b6a64626353c Matrix topology example program
Egemen K. Cetinkaya <ekc@ittc.ku.edu>
parents:
diff changeset
   185
b6a64626353c Matrix topology example program
Egemen K. Cetinkaya <ekc@ittc.ku.edu>
parents:
diff changeset
   186
  // ---------- End of Network Set-up ----------------------------------------
b6a64626353c Matrix topology example program
Egemen K. Cetinkaya <ekc@ittc.ku.edu>
parents:
diff changeset
   187
b6a64626353c Matrix topology example program
Egemen K. Cetinkaya <ekc@ittc.ku.edu>
parents:
diff changeset
   188
  // ---------- Allocate Node Positions --------------------------------------
b6a64626353c Matrix topology example program
Egemen K. Cetinkaya <ekc@ittc.ku.edu>
parents:
diff changeset
   189
b6a64626353c Matrix topology example program
Egemen K. Cetinkaya <ekc@ittc.ku.edu>
parents:
diff changeset
   190
  NS_LOG_INFO ("Allocate Positions to Nodes.");
b6a64626353c Matrix topology example program
Egemen K. Cetinkaya <ekc@ittc.ku.edu>
parents:
diff changeset
   191
b6a64626353c Matrix topology example program
Egemen K. Cetinkaya <ekc@ittc.ku.edu>
parents:
diff changeset
   192
  MobilityHelper mobility_n;
b6a64626353c Matrix topology example program
Egemen K. Cetinkaya <ekc@ittc.ku.edu>
parents:
diff changeset
   193
  Ptr<ListPositionAllocator> positionAlloc_n = CreateObject<ListPositionAllocator> ();
b6a64626353c Matrix topology example program
Egemen K. Cetinkaya <ekc@ittc.ku.edu>
parents:
diff changeset
   194
b6a64626353c Matrix topology example program
Egemen K. Cetinkaya <ekc@ittc.ku.edu>
parents:
diff changeset
   195
  for (size_t m = 0; m < coord_array.size (); m++)
b6a64626353c Matrix topology example program
Egemen K. Cetinkaya <ekc@ittc.ku.edu>
parents:
diff changeset
   196
    {
b6a64626353c Matrix topology example program
Egemen K. Cetinkaya <ekc@ittc.ku.edu>
parents:
diff changeset
   197
      positionAlloc_n->Add (Vector (coord_array[m][0], coord_array[m][1], 0));
b6a64626353c Matrix topology example program
Egemen K. Cetinkaya <ekc@ittc.ku.edu>
parents:
diff changeset
   198
      Ptr<Node> n0 = nodes.Get (m);
b6a64626353c Matrix topology example program
Egemen K. Cetinkaya <ekc@ittc.ku.edu>
parents:
diff changeset
   199
      Ptr<CanvasLocation> nLoc =  n0->GetObject<CanvasLocation> ();
b6a64626353c Matrix topology example program
Egemen K. Cetinkaya <ekc@ittc.ku.edu>
parents:
diff changeset
   200
      if (nLoc == 0)
b6a64626353c Matrix topology example program
Egemen K. Cetinkaya <ekc@ittc.ku.edu>
parents:
diff changeset
   201
        {
b6a64626353c Matrix topology example program
Egemen K. Cetinkaya <ekc@ittc.ku.edu>
parents:
diff changeset
   202
          nLoc = CreateObject<CanvasLocation> ();
b6a64626353c Matrix topology example program
Egemen K. Cetinkaya <ekc@ittc.ku.edu>
parents:
diff changeset
   203
          n0->AggregateObject (nLoc);
b6a64626353c Matrix topology example program
Egemen K. Cetinkaya <ekc@ittc.ku.edu>
parents:
diff changeset
   204
        }
b6a64626353c Matrix topology example program
Egemen K. Cetinkaya <ekc@ittc.ku.edu>
parents:
diff changeset
   205
      // y-coordinates are negated for correct display in NetAnim
b6a64626353c Matrix topology example program
Egemen K. Cetinkaya <ekc@ittc.ku.edu>
parents:
diff changeset
   206
      // NetAnim's (0,0) reference coordinates are located on upper left corner
b6a64626353c Matrix topology example program
Egemen K. Cetinkaya <ekc@ittc.ku.edu>
parents:
diff changeset
   207
      // by negating the y coordinates, we declare the reference (0,0) coordinate
b6a64626353c Matrix topology example program
Egemen K. Cetinkaya <ekc@ittc.ku.edu>
parents:
diff changeset
   208
      // to the bottom left corner
b6a64626353c Matrix topology example program
Egemen K. Cetinkaya <ekc@ittc.ku.edu>
parents:
diff changeset
   209
      Vector nVec (coord_array[m][0], -coord_array[m][1], 0);
b6a64626353c Matrix topology example program
Egemen K. Cetinkaya <ekc@ittc.ku.edu>
parents:
diff changeset
   210
      nLoc->SetLocation (nVec);
b6a64626353c Matrix topology example program
Egemen K. Cetinkaya <ekc@ittc.ku.edu>
parents:
diff changeset
   211
b6a64626353c Matrix topology example program
Egemen K. Cetinkaya <ekc@ittc.ku.edu>
parents:
diff changeset
   212
    }
b6a64626353c Matrix topology example program
Egemen K. Cetinkaya <ekc@ittc.ku.edu>
parents:
diff changeset
   213
  mobility_n.SetPositionAllocator (positionAlloc_n);
b6a64626353c Matrix topology example program
Egemen K. Cetinkaya <ekc@ittc.ku.edu>
parents:
diff changeset
   214
  mobility_n.Install (nodes);
b6a64626353c Matrix topology example program
Egemen K. Cetinkaya <ekc@ittc.ku.edu>
parents:
diff changeset
   215
b6a64626353c Matrix topology example program
Egemen K. Cetinkaya <ekc@ittc.ku.edu>
parents:
diff changeset
   216
  // ---------- End of Allocate Node Positions -------------------------------
b6a64626353c Matrix topology example program
Egemen K. Cetinkaya <ekc@ittc.ku.edu>
parents:
diff changeset
   217
b6a64626353c Matrix topology example program
Egemen K. Cetinkaya <ekc@ittc.ku.edu>
parents:
diff changeset
   218
  // ---------- Create n*(n-1) CBR Flows -------------------------------------
b6a64626353c Matrix topology example program
Egemen K. Cetinkaya <ekc@ittc.ku.edu>
parents:
diff changeset
   219
b6a64626353c Matrix topology example program
Egemen K. Cetinkaya <ekc@ittc.ku.edu>
parents:
diff changeset
   220
  NS_LOG_INFO ("Setup Packet Sinks.");
b6a64626353c Matrix topology example program
Egemen K. Cetinkaya <ekc@ittc.ku.edu>
parents:
diff changeset
   221
b6a64626353c Matrix topology example program
Egemen K. Cetinkaya <ekc@ittc.ku.edu>
parents:
diff changeset
   222
  uint16_t port = 9;
b6a64626353c Matrix topology example program
Egemen K. Cetinkaya <ekc@ittc.ku.edu>
parents:
diff changeset
   223
b6a64626353c Matrix topology example program
Egemen K. Cetinkaya <ekc@ittc.ku.edu>
parents:
diff changeset
   224
  for (int i = 0; i < n_nodes; i++)
b6a64626353c Matrix topology example program
Egemen K. Cetinkaya <ekc@ittc.ku.edu>
parents:
diff changeset
   225
    {
b6a64626353c Matrix topology example program
Egemen K. Cetinkaya <ekc@ittc.ku.edu>
parents:
diff changeset
   226
      PacketSinkHelper sink ("ns3::UdpSocketFactory", InetSocketAddress (Ipv4Address::GetAny (), port));
b6a64626353c Matrix topology example program
Egemen K. Cetinkaya <ekc@ittc.ku.edu>
parents:
diff changeset
   227
      ApplicationContainer apps_sink = sink.Install (nodes.Get (i));   // sink is installed on all nodes
b6a64626353c Matrix topology example program
Egemen K. Cetinkaya <ekc@ittc.ku.edu>
parents:
diff changeset
   228
      apps_sink.Start (Seconds (SinkStartTime));
b6a64626353c Matrix topology example program
Egemen K. Cetinkaya <ekc@ittc.ku.edu>
parents:
diff changeset
   229
      apps_sink.Stop (Seconds (SinkStopTime));
b6a64626353c Matrix topology example program
Egemen K. Cetinkaya <ekc@ittc.ku.edu>
parents:
diff changeset
   230
    }
b6a64626353c Matrix topology example program
Egemen K. Cetinkaya <ekc@ittc.ku.edu>
parents:
diff changeset
   231
b6a64626353c Matrix topology example program
Egemen K. Cetinkaya <ekc@ittc.ku.edu>
parents:
diff changeset
   232
  NS_LOG_INFO ("Setup CBR Traffic Sources.");
b6a64626353c Matrix topology example program
Egemen K. Cetinkaya <ekc@ittc.ku.edu>
parents:
diff changeset
   233
b6a64626353c Matrix topology example program
Egemen K. Cetinkaya <ekc@ittc.ku.edu>
parents:
diff changeset
   234
  for (int i = 0; i < n_nodes; i++)
b6a64626353c Matrix topology example program
Egemen K. Cetinkaya <ekc@ittc.ku.edu>
parents:
diff changeset
   235
    {
b6a64626353c Matrix topology example program
Egemen K. Cetinkaya <ekc@ittc.ku.edu>
parents:
diff changeset
   236
      for (int j = 0; j < n_nodes; j++)
b6a64626353c Matrix topology example program
Egemen K. Cetinkaya <ekc@ittc.ku.edu>
parents:
diff changeset
   237
        {
b6a64626353c Matrix topology example program
Egemen K. Cetinkaya <ekc@ittc.ku.edu>
parents:
diff changeset
   238
          if (i != j)
b6a64626353c Matrix topology example program
Egemen K. Cetinkaya <ekc@ittc.ku.edu>
parents:
diff changeset
   239
            {
b6a64626353c Matrix topology example program
Egemen K. Cetinkaya <ekc@ittc.ku.edu>
parents:
diff changeset
   240
b6a64626353c Matrix topology example program
Egemen K. Cetinkaya <ekc@ittc.ku.edu>
parents:
diff changeset
   241
              // We needed to generate a random number (rn) to be used to eliminate
b6a64626353c Matrix topology example program
Egemen K. Cetinkaya <ekc@ittc.ku.edu>
parents:
diff changeset
   242
              // the artificial congestion caused by sending the packets at the
b6a64626353c Matrix topology example program
Egemen K. Cetinkaya <ekc@ittc.ku.edu>
parents:
diff changeset
   243
              // same time. This rn is added to AppStartTime to have the sources
b6a64626353c Matrix topology example program
Egemen K. Cetinkaya <ekc@ittc.ku.edu>
parents:
diff changeset
   244
              // start at different time, however they will still send at the same rate.
b6a64626353c Matrix topology example program
Egemen K. Cetinkaya <ekc@ittc.ku.edu>
parents:
diff changeset
   245
b6a64626353c Matrix topology example program
Egemen K. Cetinkaya <ekc@ittc.ku.edu>
parents:
diff changeset
   246
              UniformVariable x (0,1);
b6a64626353c Matrix topology example program
Egemen K. Cetinkaya <ekc@ittc.ku.edu>
parents:
diff changeset
   247
              double rn = x.GetValue ();
b6a64626353c Matrix topology example program
Egemen K. Cetinkaya <ekc@ittc.ku.edu>
parents:
diff changeset
   248
              Ptr<Node> n = nodes.Get (j);
b6a64626353c Matrix topology example program
Egemen K. Cetinkaya <ekc@ittc.ku.edu>
parents:
diff changeset
   249
              Ptr<Ipv4> ipv4 = n->GetObject<Ipv4> ();
b6a64626353c Matrix topology example program
Egemen K. Cetinkaya <ekc@ittc.ku.edu>
parents:
diff changeset
   250
              Ipv4InterfaceAddress ipv4_int_addr = ipv4->GetAddress (1, 0);
b6a64626353c Matrix topology example program
Egemen K. Cetinkaya <ekc@ittc.ku.edu>
parents:
diff changeset
   251
              Ipv4Address ip_addr = ipv4_int_addr.GetLocal ();
b6a64626353c Matrix topology example program
Egemen K. Cetinkaya <ekc@ittc.ku.edu>
parents:
diff changeset
   252
              OnOffHelper onoff ("ns3::UdpSocketFactory", InetSocketAddress (ip_addr, port)); // traffic flows from node[i] to node[j]
b6a64626353c Matrix topology example program
Egemen K. Cetinkaya <ekc@ittc.ku.edu>
parents:
diff changeset
   253
              onoff.SetAttribute ("OnTime", RandomVariableValue (ConstantVariable  (1)));
b6a64626353c Matrix topology example program
Egemen K. Cetinkaya <ekc@ittc.ku.edu>
parents:
diff changeset
   254
              onoff.SetAttribute ("OffTime", RandomVariableValue (ConstantVariable (0)));
b6a64626353c Matrix topology example program
Egemen K. Cetinkaya <ekc@ittc.ku.edu>
parents:
diff changeset
   255
              ApplicationContainer apps = onoff.Install (nodes.Get (i));  // traffic sources are installed on all nodes
b6a64626353c Matrix topology example program
Egemen K. Cetinkaya <ekc@ittc.ku.edu>
parents:
diff changeset
   256
              apps.Start (Seconds (AppStartTime + rn));
b6a64626353c Matrix topology example program
Egemen K. Cetinkaya <ekc@ittc.ku.edu>
parents:
diff changeset
   257
              apps.Stop (Seconds (AppStopTime));
b6a64626353c Matrix topology example program
Egemen K. Cetinkaya <ekc@ittc.ku.edu>
parents:
diff changeset
   258
            }
b6a64626353c Matrix topology example program
Egemen K. Cetinkaya <ekc@ittc.ku.edu>
parents:
diff changeset
   259
        }
b6a64626353c Matrix topology example program
Egemen K. Cetinkaya <ekc@ittc.ku.edu>
parents:
diff changeset
   260
    }
b6a64626353c Matrix topology example program
Egemen K. Cetinkaya <ekc@ittc.ku.edu>
parents:
diff changeset
   261
b6a64626353c Matrix topology example program
Egemen K. Cetinkaya <ekc@ittc.ku.edu>
parents:
diff changeset
   262
  // ---------- End of Create n*(n-1) CBR Flows ------------------------------
b6a64626353c Matrix topology example program
Egemen K. Cetinkaya <ekc@ittc.ku.edu>
parents:
diff changeset
   263
b6a64626353c Matrix topology example program
Egemen K. Cetinkaya <ekc@ittc.ku.edu>
parents:
diff changeset
   264
  // ---------- Simulation Monitoring ----------------------------------------
b6a64626353c Matrix topology example program
Egemen K. Cetinkaya <ekc@ittc.ku.edu>
parents:
diff changeset
   265
b6a64626353c Matrix topology example program
Egemen K. Cetinkaya <ekc@ittc.ku.edu>
parents:
diff changeset
   266
  NS_LOG_INFO ("Configure Tracing.");
b6a64626353c Matrix topology example program
Egemen K. Cetinkaya <ekc@ittc.ku.edu>
parents:
diff changeset
   267
b6a64626353c Matrix topology example program
Egemen K. Cetinkaya <ekc@ittc.ku.edu>
parents:
diff changeset
   268
  AsciiTraceHelper ascii;
b6a64626353c Matrix topology example program
Egemen K. Cetinkaya <ekc@ittc.ku.edu>
parents:
diff changeset
   269
  p2p.EnableAsciiAll (ascii.CreateFileStream (tr_name.c_str ()));
b6a64626353c Matrix topology example program
Egemen K. Cetinkaya <ekc@ittc.ku.edu>
parents:
diff changeset
   270
  // p2p.EnablePcapAll (pcap_name.c_str());
b6a64626353c Matrix topology example program
Egemen K. Cetinkaya <ekc@ittc.ku.edu>
parents:
diff changeset
   271
b6a64626353c Matrix topology example program
Egemen K. Cetinkaya <ekc@ittc.ku.edu>
parents:
diff changeset
   272
  // Ptr<FlowMonitor> flowmon;
b6a64626353c Matrix topology example program
Egemen K. Cetinkaya <ekc@ittc.ku.edu>
parents:
diff changeset
   273
  // FlowMonitorHelper flowmonHelper;
b6a64626353c Matrix topology example program
Egemen K. Cetinkaya <ekc@ittc.ku.edu>
parents:
diff changeset
   274
  // flowmon = flowmonHelper.InstallAll ();
b6a64626353c Matrix topology example program
Egemen K. Cetinkaya <ekc@ittc.ku.edu>
parents:
diff changeset
   275
b6a64626353c Matrix topology example program
Egemen K. Cetinkaya <ekc@ittc.ku.edu>
parents:
diff changeset
   276
  // Configure animator with default settings
b6a64626353c Matrix topology example program
Egemen K. Cetinkaya <ekc@ittc.ku.edu>
parents:
diff changeset
   277
b6a64626353c Matrix topology example program
Egemen K. Cetinkaya <ekc@ittc.ku.edu>
parents:
diff changeset
   278
  bool animEnabled = false;
b6a64626353c Matrix topology example program
Egemen K. Cetinkaya <ekc@ittc.ku.edu>
parents:
diff changeset
   279
  AnimationInterface anim;
b6a64626353c Matrix topology example program
Egemen K. Cetinkaya <ekc@ittc.ku.edu>
parents:
diff changeset
   280
  if (anim.SetServerPort (9) && anim.SetOutputFile (anim_name.c_str ()))
b6a64626353c Matrix topology example program
Egemen K. Cetinkaya <ekc@ittc.ku.edu>
parents:
diff changeset
   281
    {  
b6a64626353c Matrix topology example program
Egemen K. Cetinkaya <ekc@ittc.ku.edu>
parents:
diff changeset
   282
      NS_LOG_INFO ("Animation Interface Enabled.");
b6a64626353c Matrix topology example program
Egemen K. Cetinkaya <ekc@ittc.ku.edu>
parents:
diff changeset
   283
      animEnabled = true;
b6a64626353c Matrix topology example program
Egemen K. Cetinkaya <ekc@ittc.ku.edu>
parents:
diff changeset
   284
      anim.StartAnimation ();
b6a64626353c Matrix topology example program
Egemen K. Cetinkaya <ekc@ittc.ku.edu>
parents:
diff changeset
   285
    }
b6a64626353c Matrix topology example program
Egemen K. Cetinkaya <ekc@ittc.ku.edu>
parents:
diff changeset
   286
b6a64626353c Matrix topology example program
Egemen K. Cetinkaya <ekc@ittc.ku.edu>
parents:
diff changeset
   287
  NS_LOG_INFO ("Run Simulation.");
b6a64626353c Matrix topology example program
Egemen K. Cetinkaya <ekc@ittc.ku.edu>
parents:
diff changeset
   288
b6a64626353c Matrix topology example program
Egemen K. Cetinkaya <ekc@ittc.ku.edu>
parents:
diff changeset
   289
  Simulator::Stop (Seconds (SimTime));
b6a64626353c Matrix topology example program
Egemen K. Cetinkaya <ekc@ittc.ku.edu>
parents:
diff changeset
   290
  Simulator::Run ();
b6a64626353c Matrix topology example program
Egemen K. Cetinkaya <ekc@ittc.ku.edu>
parents:
diff changeset
   291
  // flowmon->SerializeToXmlFile (flow_name.c_str(), true, true);
b6a64626353c Matrix topology example program
Egemen K. Cetinkaya <ekc@ittc.ku.edu>
parents:
diff changeset
   292
  if (animEnabled)
b6a64626353c Matrix topology example program
Egemen K. Cetinkaya <ekc@ittc.ku.edu>
parents:
diff changeset
   293
    {
b6a64626353c Matrix topology example program
Egemen K. Cetinkaya <ekc@ittc.ku.edu>
parents:
diff changeset
   294
      anim.StopAnimation ();
b6a64626353c Matrix topology example program
Egemen K. Cetinkaya <ekc@ittc.ku.edu>
parents:
diff changeset
   295
    }
b6a64626353c Matrix topology example program
Egemen K. Cetinkaya <ekc@ittc.ku.edu>
parents:
diff changeset
   296
  Simulator::Destroy ();
b6a64626353c Matrix topology example program
Egemen K. Cetinkaya <ekc@ittc.ku.edu>
parents:
diff changeset
   297
b6a64626353c Matrix topology example program
Egemen K. Cetinkaya <ekc@ittc.ku.edu>
parents:
diff changeset
   298
  // ---------- End of Simulation Monitoring ---------------------------------
b6a64626353c Matrix topology example program
Egemen K. Cetinkaya <ekc@ittc.ku.edu>
parents:
diff changeset
   299
b6a64626353c Matrix topology example program
Egemen K. Cetinkaya <ekc@ittc.ku.edu>
parents:
diff changeset
   300
  return 0;
b6a64626353c Matrix topology example program
Egemen K. Cetinkaya <ekc@ittc.ku.edu>
parents:
diff changeset
   301
b6a64626353c Matrix topology example program
Egemen K. Cetinkaya <ekc@ittc.ku.edu>
parents:
diff changeset
   302
}
b6a64626353c Matrix topology example program
Egemen K. Cetinkaya <ekc@ittc.ku.edu>
parents:
diff changeset
   303
b6a64626353c Matrix topology example program
Egemen K. Cetinkaya <ekc@ittc.ku.edu>
parents:
diff changeset
   304
// ---------- Function Definitions -------------------------------------------
b6a64626353c Matrix topology example program
Egemen K. Cetinkaya <ekc@ittc.ku.edu>
parents:
diff changeset
   305
b6a64626353c Matrix topology example program
Egemen K. Cetinkaya <ekc@ittc.ku.edu>
parents:
diff changeset
   306
vector<vector<bool> > readNxNMatrix (std::string adj_mat_file_name)
b6a64626353c Matrix topology example program
Egemen K. Cetinkaya <ekc@ittc.ku.edu>
parents:
diff changeset
   307
{
b6a64626353c Matrix topology example program
Egemen K. Cetinkaya <ekc@ittc.ku.edu>
parents:
diff changeset
   308
  ifstream adj_mat_file;
b6a64626353c Matrix topology example program
Egemen K. Cetinkaya <ekc@ittc.ku.edu>
parents:
diff changeset
   309
  adj_mat_file.open (adj_mat_file_name.c_str (), ios::in);
b6a64626353c Matrix topology example program
Egemen K. Cetinkaya <ekc@ittc.ku.edu>
parents:
diff changeset
   310
  if (adj_mat_file.fail ())
b6a64626353c Matrix topology example program
Egemen K. Cetinkaya <ekc@ittc.ku.edu>
parents:
diff changeset
   311
    {
b6a64626353c Matrix topology example program
Egemen K. Cetinkaya <ekc@ittc.ku.edu>
parents:
diff changeset
   312
      NS_FATAL_ERROR ("File " << adj_mat_file_name.c_str () << " not found");
b6a64626353c Matrix topology example program
Egemen K. Cetinkaya <ekc@ittc.ku.edu>
parents:
diff changeset
   313
    }
b6a64626353c Matrix topology example program
Egemen K. Cetinkaya <ekc@ittc.ku.edu>
parents:
diff changeset
   314
  vector<vector<bool> > array;
b6a64626353c Matrix topology example program
Egemen K. Cetinkaya <ekc@ittc.ku.edu>
parents:
diff changeset
   315
  int i = 0;
b6a64626353c Matrix topology example program
Egemen K. Cetinkaya <ekc@ittc.ku.edu>
parents:
diff changeset
   316
  int n_nodes = 0;
b6a64626353c Matrix topology example program
Egemen K. Cetinkaya <ekc@ittc.ku.edu>
parents:
diff changeset
   317
b6a64626353c Matrix topology example program
Egemen K. Cetinkaya <ekc@ittc.ku.edu>
parents:
diff changeset
   318
  while (!adj_mat_file.eof ())
b6a64626353c Matrix topology example program
Egemen K. Cetinkaya <ekc@ittc.ku.edu>
parents:
diff changeset
   319
    {
b6a64626353c Matrix topology example program
Egemen K. Cetinkaya <ekc@ittc.ku.edu>
parents:
diff changeset
   320
      string line;
b6a64626353c Matrix topology example program
Egemen K. Cetinkaya <ekc@ittc.ku.edu>
parents:
diff changeset
   321
      getline (adj_mat_file, line);
b6a64626353c Matrix topology example program
Egemen K. Cetinkaya <ekc@ittc.ku.edu>
parents:
diff changeset
   322
      if (line == "")
b6a64626353c Matrix topology example program
Egemen K. Cetinkaya <ekc@ittc.ku.edu>
parents:
diff changeset
   323
        {
b6a64626353c Matrix topology example program
Egemen K. Cetinkaya <ekc@ittc.ku.edu>
parents:
diff changeset
   324
          NS_LOG_WARN ("WARNING: Ignoring blank row in the array: " << i);
b6a64626353c Matrix topology example program
Egemen K. Cetinkaya <ekc@ittc.ku.edu>
parents:
diff changeset
   325
          break;
b6a64626353c Matrix topology example program
Egemen K. Cetinkaya <ekc@ittc.ku.edu>
parents:
diff changeset
   326
        }
b6a64626353c Matrix topology example program
Egemen K. Cetinkaya <ekc@ittc.ku.edu>
parents:
diff changeset
   327
b6a64626353c Matrix topology example program
Egemen K. Cetinkaya <ekc@ittc.ku.edu>
parents:
diff changeset
   328
      istringstream iss (line);
b6a64626353c Matrix topology example program
Egemen K. Cetinkaya <ekc@ittc.ku.edu>
parents:
diff changeset
   329
      bool element;
b6a64626353c Matrix topology example program
Egemen K. Cetinkaya <ekc@ittc.ku.edu>
parents:
diff changeset
   330
      vector<bool> row;
b6a64626353c Matrix topology example program
Egemen K. Cetinkaya <ekc@ittc.ku.edu>
parents:
diff changeset
   331
      int j = 0;
b6a64626353c Matrix topology example program
Egemen K. Cetinkaya <ekc@ittc.ku.edu>
parents:
diff changeset
   332
b6a64626353c Matrix topology example program
Egemen K. Cetinkaya <ekc@ittc.ku.edu>
parents:
diff changeset
   333
      while (iss >> element)
b6a64626353c Matrix topology example program
Egemen K. Cetinkaya <ekc@ittc.ku.edu>
parents:
diff changeset
   334
        {
b6a64626353c Matrix topology example program
Egemen K. Cetinkaya <ekc@ittc.ku.edu>
parents:
diff changeset
   335
          row.push_back (element);
b6a64626353c Matrix topology example program
Egemen K. Cetinkaya <ekc@ittc.ku.edu>
parents:
diff changeset
   336
          j++;
b6a64626353c Matrix topology example program
Egemen K. Cetinkaya <ekc@ittc.ku.edu>
parents:
diff changeset
   337
        }
b6a64626353c Matrix topology example program
Egemen K. Cetinkaya <ekc@ittc.ku.edu>
parents:
diff changeset
   338
b6a64626353c Matrix topology example program
Egemen K. Cetinkaya <ekc@ittc.ku.edu>
parents:
diff changeset
   339
      if (i == 0)
b6a64626353c Matrix topology example program
Egemen K. Cetinkaya <ekc@ittc.ku.edu>
parents:
diff changeset
   340
        {
b6a64626353c Matrix topology example program
Egemen K. Cetinkaya <ekc@ittc.ku.edu>
parents:
diff changeset
   341
          n_nodes = j;
b6a64626353c Matrix topology example program
Egemen K. Cetinkaya <ekc@ittc.ku.edu>
parents:
diff changeset
   342
        }
b6a64626353c Matrix topology example program
Egemen K. Cetinkaya <ekc@ittc.ku.edu>
parents:
diff changeset
   343
b6a64626353c Matrix topology example program
Egemen K. Cetinkaya <ekc@ittc.ku.edu>
parents:
diff changeset
   344
      if (j != n_nodes )
b6a64626353c Matrix topology example program
Egemen K. Cetinkaya <ekc@ittc.ku.edu>
parents:
diff changeset
   345
        {
b6a64626353c Matrix topology example program
Egemen K. Cetinkaya <ekc@ittc.ku.edu>
parents:
diff changeset
   346
          NS_LOG_ERROR ("ERROR: Number of elements in line " << i << ": " << j << " not equal to number of elements in line 0: " << n_nodes);
b6a64626353c Matrix topology example program
Egemen K. Cetinkaya <ekc@ittc.ku.edu>
parents:
diff changeset
   347
          NS_FATAL_ERROR ("ERROR: The number of rows is not equal to the number of columns! in the adjacency matrix");
b6a64626353c Matrix topology example program
Egemen K. Cetinkaya <ekc@ittc.ku.edu>
parents:
diff changeset
   348
        }
b6a64626353c Matrix topology example program
Egemen K. Cetinkaya <ekc@ittc.ku.edu>
parents:
diff changeset
   349
      else
b6a64626353c Matrix topology example program
Egemen K. Cetinkaya <ekc@ittc.ku.edu>
parents:
diff changeset
   350
        {
b6a64626353c Matrix topology example program
Egemen K. Cetinkaya <ekc@ittc.ku.edu>
parents:
diff changeset
   351
          array.push_back (row);
b6a64626353c Matrix topology example program
Egemen K. Cetinkaya <ekc@ittc.ku.edu>
parents:
diff changeset
   352
        }
b6a64626353c Matrix topology example program
Egemen K. Cetinkaya <ekc@ittc.ku.edu>
parents:
diff changeset
   353
      i++;
b6a64626353c Matrix topology example program
Egemen K. Cetinkaya <ekc@ittc.ku.edu>
parents:
diff changeset
   354
    }
b6a64626353c Matrix topology example program
Egemen K. Cetinkaya <ekc@ittc.ku.edu>
parents:
diff changeset
   355
b6a64626353c Matrix topology example program
Egemen K. Cetinkaya <ekc@ittc.ku.edu>
parents:
diff changeset
   356
  if (i != n_nodes)
b6a64626353c Matrix topology example program
Egemen K. Cetinkaya <ekc@ittc.ku.edu>
parents:
diff changeset
   357
    {
b6a64626353c Matrix topology example program
Egemen K. Cetinkaya <ekc@ittc.ku.edu>
parents:
diff changeset
   358
      NS_LOG_ERROR ("There are " << i << " rows and " << n_nodes << " columns.");
b6a64626353c Matrix topology example program
Egemen K. Cetinkaya <ekc@ittc.ku.edu>
parents:
diff changeset
   359
      NS_FATAL_ERROR ("ERROR: The number of rows is not equal to the number of columns! in the adjacency matrix");
b6a64626353c Matrix topology example program
Egemen K. Cetinkaya <ekc@ittc.ku.edu>
parents:
diff changeset
   360
    }
b6a64626353c Matrix topology example program
Egemen K. Cetinkaya <ekc@ittc.ku.edu>
parents:
diff changeset
   361
b6a64626353c Matrix topology example program
Egemen K. Cetinkaya <ekc@ittc.ku.edu>
parents:
diff changeset
   362
  adj_mat_file.close ();
b6a64626353c Matrix topology example program
Egemen K. Cetinkaya <ekc@ittc.ku.edu>
parents:
diff changeset
   363
  return array;
b6a64626353c Matrix topology example program
Egemen K. Cetinkaya <ekc@ittc.ku.edu>
parents:
diff changeset
   364
b6a64626353c Matrix topology example program
Egemen K. Cetinkaya <ekc@ittc.ku.edu>
parents:
diff changeset
   365
}
b6a64626353c Matrix topology example program
Egemen K. Cetinkaya <ekc@ittc.ku.edu>
parents:
diff changeset
   366
b6a64626353c Matrix topology example program
Egemen K. Cetinkaya <ekc@ittc.ku.edu>
parents:
diff changeset
   367
vector<vector<double> > readCordinatesFile (std::string node_coordinates_file_name)
b6a64626353c Matrix topology example program
Egemen K. Cetinkaya <ekc@ittc.ku.edu>
parents:
diff changeset
   368
{
b6a64626353c Matrix topology example program
Egemen K. Cetinkaya <ekc@ittc.ku.edu>
parents:
diff changeset
   369
  ifstream node_coordinates_file;
b6a64626353c Matrix topology example program
Egemen K. Cetinkaya <ekc@ittc.ku.edu>
parents:
diff changeset
   370
  node_coordinates_file.open (node_coordinates_file_name.c_str (), ios::in);
b6a64626353c Matrix topology example program
Egemen K. Cetinkaya <ekc@ittc.ku.edu>
parents:
diff changeset
   371
  if (node_coordinates_file.fail ())
b6a64626353c Matrix topology example program
Egemen K. Cetinkaya <ekc@ittc.ku.edu>
parents:
diff changeset
   372
    {
b6a64626353c Matrix topology example program
Egemen K. Cetinkaya <ekc@ittc.ku.edu>
parents:
diff changeset
   373
      NS_FATAL_ERROR ("File " << node_coordinates_file_name.c_str () << " not found");
b6a64626353c Matrix topology example program
Egemen K. Cetinkaya <ekc@ittc.ku.edu>
parents:
diff changeset
   374
    }
b6a64626353c Matrix topology example program
Egemen K. Cetinkaya <ekc@ittc.ku.edu>
parents:
diff changeset
   375
  vector<vector<double> > coord_array;
b6a64626353c Matrix topology example program
Egemen K. Cetinkaya <ekc@ittc.ku.edu>
parents:
diff changeset
   376
  int m = 0;
b6a64626353c Matrix topology example program
Egemen K. Cetinkaya <ekc@ittc.ku.edu>
parents:
diff changeset
   377
b6a64626353c Matrix topology example program
Egemen K. Cetinkaya <ekc@ittc.ku.edu>
parents:
diff changeset
   378
  while (!node_coordinates_file.eof ())
b6a64626353c Matrix topology example program
Egemen K. Cetinkaya <ekc@ittc.ku.edu>
parents:
diff changeset
   379
    {
b6a64626353c Matrix topology example program
Egemen K. Cetinkaya <ekc@ittc.ku.edu>
parents:
diff changeset
   380
      string line;
b6a64626353c Matrix topology example program
Egemen K. Cetinkaya <ekc@ittc.ku.edu>
parents:
diff changeset
   381
      getline (node_coordinates_file, line);
b6a64626353c Matrix topology example program
Egemen K. Cetinkaya <ekc@ittc.ku.edu>
parents:
diff changeset
   382
b6a64626353c Matrix topology example program
Egemen K. Cetinkaya <ekc@ittc.ku.edu>
parents:
diff changeset
   383
      if (line == "")
b6a64626353c Matrix topology example program
Egemen K. Cetinkaya <ekc@ittc.ku.edu>
parents:
diff changeset
   384
        {
b6a64626353c Matrix topology example program
Egemen K. Cetinkaya <ekc@ittc.ku.edu>
parents:
diff changeset
   385
          NS_LOG_WARN ("WARNING: Ignoring blank row: " << m);
b6a64626353c Matrix topology example program
Egemen K. Cetinkaya <ekc@ittc.ku.edu>
parents:
diff changeset
   386
          break;
b6a64626353c Matrix topology example program
Egemen K. Cetinkaya <ekc@ittc.ku.edu>
parents:
diff changeset
   387
        }
b6a64626353c Matrix topology example program
Egemen K. Cetinkaya <ekc@ittc.ku.edu>
parents:
diff changeset
   388
b6a64626353c Matrix topology example program
Egemen K. Cetinkaya <ekc@ittc.ku.edu>
parents:
diff changeset
   389
      istringstream iss (line);
b6a64626353c Matrix topology example program
Egemen K. Cetinkaya <ekc@ittc.ku.edu>
parents:
diff changeset
   390
      double coordinate;
b6a64626353c Matrix topology example program
Egemen K. Cetinkaya <ekc@ittc.ku.edu>
parents:
diff changeset
   391
      vector<double> row;
b6a64626353c Matrix topology example program
Egemen K. Cetinkaya <ekc@ittc.ku.edu>
parents:
diff changeset
   392
      int n = 0;
b6a64626353c Matrix topology example program
Egemen K. Cetinkaya <ekc@ittc.ku.edu>
parents:
diff changeset
   393
      while (iss >> coordinate)
b6a64626353c Matrix topology example program
Egemen K. Cetinkaya <ekc@ittc.ku.edu>
parents:
diff changeset
   394
        {
b6a64626353c Matrix topology example program
Egemen K. Cetinkaya <ekc@ittc.ku.edu>
parents:
diff changeset
   395
          row.push_back (coordinate);
b6a64626353c Matrix topology example program
Egemen K. Cetinkaya <ekc@ittc.ku.edu>
parents:
diff changeset
   396
          n++;
b6a64626353c Matrix topology example program
Egemen K. Cetinkaya <ekc@ittc.ku.edu>
parents:
diff changeset
   397
        }
b6a64626353c Matrix topology example program
Egemen K. Cetinkaya <ekc@ittc.ku.edu>
parents:
diff changeset
   398
b6a64626353c Matrix topology example program
Egemen K. Cetinkaya <ekc@ittc.ku.edu>
parents:
diff changeset
   399
      if (n != 2)
b6a64626353c Matrix topology example program
Egemen K. Cetinkaya <ekc@ittc.ku.edu>
parents:
diff changeset
   400
        {
b6a64626353c Matrix topology example program
Egemen K. Cetinkaya <ekc@ittc.ku.edu>
parents:
diff changeset
   401
          NS_LOG_ERROR ("ERROR: Number of elements at line#" << m << " is "  << n << " which is not equal to 2 for node coordinates file");
b6a64626353c Matrix topology example program
Egemen K. Cetinkaya <ekc@ittc.ku.edu>
parents:
diff changeset
   402
          exit (1);
b6a64626353c Matrix topology example program
Egemen K. Cetinkaya <ekc@ittc.ku.edu>
parents:
diff changeset
   403
        }
b6a64626353c Matrix topology example program
Egemen K. Cetinkaya <ekc@ittc.ku.edu>
parents:
diff changeset
   404
b6a64626353c Matrix topology example program
Egemen K. Cetinkaya <ekc@ittc.ku.edu>
parents:
diff changeset
   405
      else
b6a64626353c Matrix topology example program
Egemen K. Cetinkaya <ekc@ittc.ku.edu>
parents:
diff changeset
   406
        {
b6a64626353c Matrix topology example program
Egemen K. Cetinkaya <ekc@ittc.ku.edu>
parents:
diff changeset
   407
          coord_array.push_back (row);
b6a64626353c Matrix topology example program
Egemen K. Cetinkaya <ekc@ittc.ku.edu>
parents:
diff changeset
   408
        }
b6a64626353c Matrix topology example program
Egemen K. Cetinkaya <ekc@ittc.ku.edu>
parents:
diff changeset
   409
      m++;
b6a64626353c Matrix topology example program
Egemen K. Cetinkaya <ekc@ittc.ku.edu>
parents:
diff changeset
   410
    }
b6a64626353c Matrix topology example program
Egemen K. Cetinkaya <ekc@ittc.ku.edu>
parents:
diff changeset
   411
  node_coordinates_file.close ();
b6a64626353c Matrix topology example program
Egemen K. Cetinkaya <ekc@ittc.ku.edu>
parents:
diff changeset
   412
  return coord_array;
b6a64626353c Matrix topology example program
Egemen K. Cetinkaya <ekc@ittc.ku.edu>
parents:
diff changeset
   413
b6a64626353c Matrix topology example program
Egemen K. Cetinkaya <ekc@ittc.ku.edu>
parents:
diff changeset
   414
}
b6a64626353c Matrix topology example program
Egemen K. Cetinkaya <ekc@ittc.ku.edu>
parents:
diff changeset
   415
b6a64626353c Matrix topology example program
Egemen K. Cetinkaya <ekc@ittc.ku.edu>
parents:
diff changeset
   416
void printMatrix (const char* description, vector<vector<bool> > array)
b6a64626353c Matrix topology example program
Egemen K. Cetinkaya <ekc@ittc.ku.edu>
parents:
diff changeset
   417
{
b6a64626353c Matrix topology example program
Egemen K. Cetinkaya <ekc@ittc.ku.edu>
parents:
diff changeset
   418
  cout << "**** Start " << description << "********" << endl;
b6a64626353c Matrix topology example program
Egemen K. Cetinkaya <ekc@ittc.ku.edu>
parents:
diff changeset
   419
  for (size_t m = 0; m < array.size (); m++)
b6a64626353c Matrix topology example program
Egemen K. Cetinkaya <ekc@ittc.ku.edu>
parents:
diff changeset
   420
    {
b6a64626353c Matrix topology example program
Egemen K. Cetinkaya <ekc@ittc.ku.edu>
parents:
diff changeset
   421
      for (size_t n = 0; n < array[m].size (); n++)
b6a64626353c Matrix topology example program
Egemen K. Cetinkaya <ekc@ittc.ku.edu>
parents:
diff changeset
   422
        {
b6a64626353c Matrix topology example program
Egemen K. Cetinkaya <ekc@ittc.ku.edu>
parents:
diff changeset
   423
          cout << array[m][n] << ' ';
b6a64626353c Matrix topology example program
Egemen K. Cetinkaya <ekc@ittc.ku.edu>
parents:
diff changeset
   424
        }
b6a64626353c Matrix topology example program
Egemen K. Cetinkaya <ekc@ittc.ku.edu>
parents:
diff changeset
   425
      cout << endl;
b6a64626353c Matrix topology example program
Egemen K. Cetinkaya <ekc@ittc.ku.edu>
parents:
diff changeset
   426
    }
b6a64626353c Matrix topology example program
Egemen K. Cetinkaya <ekc@ittc.ku.edu>
parents:
diff changeset
   427
  cout << "**** End " << description << "********" << endl;
b6a64626353c Matrix topology example program
Egemen K. Cetinkaya <ekc@ittc.ku.edu>
parents:
diff changeset
   428
b6a64626353c Matrix topology example program
Egemen K. Cetinkaya <ekc@ittc.ku.edu>
parents:
diff changeset
   429
}
b6a64626353c Matrix topology example program
Egemen K. Cetinkaya <ekc@ittc.ku.edu>
parents:
diff changeset
   430
b6a64626353c Matrix topology example program
Egemen K. Cetinkaya <ekc@ittc.ku.edu>
parents:
diff changeset
   431
void printCoordinateArray (const char* description, vector<vector<double> > coord_array)
b6a64626353c Matrix topology example program
Egemen K. Cetinkaya <ekc@ittc.ku.edu>
parents:
diff changeset
   432
{
b6a64626353c Matrix topology example program
Egemen K. Cetinkaya <ekc@ittc.ku.edu>
parents:
diff changeset
   433
  cout << "**** Start " << description << "********" << endl;
b6a64626353c Matrix topology example program
Egemen K. Cetinkaya <ekc@ittc.ku.edu>
parents:
diff changeset
   434
  for (size_t m = 0; m < coord_array.size (); m++)
b6a64626353c Matrix topology example program
Egemen K. Cetinkaya <ekc@ittc.ku.edu>
parents:
diff changeset
   435
    {
b6a64626353c Matrix topology example program
Egemen K. Cetinkaya <ekc@ittc.ku.edu>
parents:
diff changeset
   436
      for (size_t n = 0; n < coord_array[m].size (); n++)
b6a64626353c Matrix topology example program
Egemen K. Cetinkaya <ekc@ittc.ku.edu>
parents:
diff changeset
   437
        {
b6a64626353c Matrix topology example program
Egemen K. Cetinkaya <ekc@ittc.ku.edu>
parents:
diff changeset
   438
          cout << coord_array[m][n] << ' ';
b6a64626353c Matrix topology example program
Egemen K. Cetinkaya <ekc@ittc.ku.edu>
parents:
diff changeset
   439
        }
b6a64626353c Matrix topology example program
Egemen K. Cetinkaya <ekc@ittc.ku.edu>
parents:
diff changeset
   440
      cout << endl;
b6a64626353c Matrix topology example program
Egemen K. Cetinkaya <ekc@ittc.ku.edu>
parents:
diff changeset
   441
    }
b6a64626353c Matrix topology example program
Egemen K. Cetinkaya <ekc@ittc.ku.edu>
parents:
diff changeset
   442
  cout << "**** End " << description << "********" << endl;
b6a64626353c Matrix topology example program
Egemen K. Cetinkaya <ekc@ittc.ku.edu>
parents:
diff changeset
   443
b6a64626353c Matrix topology example program
Egemen K. Cetinkaya <ekc@ittc.ku.edu>
parents:
diff changeset
   444
}
b6a64626353c Matrix topology example program
Egemen K. Cetinkaya <ekc@ittc.ku.edu>
parents:
diff changeset
   445
b6a64626353c Matrix topology example program
Egemen K. Cetinkaya <ekc@ittc.ku.edu>
parents:
diff changeset
   446
// ---------- End of Function Definitions ------------------------------------