Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(1633)

Unified Diff: src/pgbr/model/core-calculator/genetic-algorithm/ga-core-calculator.h

Issue 15530043: New module pgbr (PGBR routing protocol) and extension of topology-read module
Patch Set: Created 10 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: src/pgbr/model/core-calculator/genetic-algorithm/ga-core-calculator.h
===================================================================
new file mode 100644
--- /dev/null
+++ b/src/pgbr/model/core-calculator/genetic-algorithm/ga-core-calculator.h
@@ -0,0 +1,168 @@
+/* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */
+/*
+ * Copyright (c) Waterford Institute of Technology, 2013, Julien Mineraud, BioFINT.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation;
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ *
+ * Author: Julien Mineraud <julien.mineraud@gmail.com>
+ *
+ * Acknowledgements:
+ * This work has received support from Science Foundation Ireland via the
+ * "A Biologically inspired framework supporting network management for
+ * the Future Internet" starting investigator award (grant no. 09/SIRG/I1643).
+ */
+
+#include <vector>
+#include "ns3/channel.h"
+#include "ns3/node.h"
+#include <stdint.h>
+#include <iostream>
+#include <math.h>
+#include "ns3/object-base.h"
+#include "ns3/traced-callback.h"
+
+#ifndef GA_CORE_CALCULATOR_H_
+#define GA_CORE_CALCULATOR_H_
+
+/*!
+ * \namespace ns3::pgbr
+ * Namespace regrouping all objects and functions to run PGBR.
+ */
+namespace ns3 {
+namespace pgbr {
+
+/*!
+ * \class GaCoreCalculator
+ * This class uses a Genetic Algorithm to calculate the core topology that ensures that the egress nodes are interconnected
+ * This class has been designed to be part of the IEEE Online GreenComm 2013 Parameterised Green Gradient Based Routing Protocol.
+ */
+class GaCoreCalculator : public ObjectBase {
+
+public:
+ /*!
+ * \brief Static function that is required for each ns3::Object.
+ *
+ * \fn static TypeId GetTypeId (void)
+ * \sa ns3::Object::GetTypeId ()
+ * \return the TypeId corresponding to the calculator
+ */
+ static TypeId GetTypeId (void);
+
+ /*!
+ * \brief Get the TypeID of this instance
+ *
+ * \fn TypeId GetInstanceTypeId (void) const
+ * \return the TypeId corresponding to this instance of the calculator
+ */
+ TypeId GetInstanceTypeId (void) const;
+
+ /*!
+ * \struct Chromosome
+ * This structure defines the chromosome used by this GA
+ */
+ struct Chromosome {
+ std::vector<Ptr<Channel> > links; /*!< The list of links */
+ std::vector<Ptr<Node> > nodes; /*!< The list of nodes */
+ };
+
+ /*!
+ * The constructor
+ */
+ GaCoreCalculator ();
+
+ /*!
+ * The destructor
+ */
+ virtual ~GaCoreCalculator ();
+
+ /*!
+ * Initialise the calculator
+ * \fn void Initialise (double_t energyRouter, double_t energyLineCard)
+ * \param energyRouter The energy in Watt used by the router's chassis
+ * \param energyLineCard The energy in Watt used by a router's line-card
+ */
+ void Initialise (double_t energyRouter, double_t energyLineCard);
+
+ /*!
+ * Generate the initial population
+ * \fn void GenerateInitialPopulation (std::vector<uint32_t> egressNodes, uint32_t populationSize)
+ * \param egressNodes The list of nodes that must be interconnected
+ * \param populationSize The size of the initial population
+ */
+ void GenerateInitialPopulation (std::vector<uint32_t> egressNodes, uint32_t populationSize);
+
+ /*!
+ * Get the best chromosome found so far
+ * \fn Chromosome GetBestChromosome ()
+ * \return the best chromosome found so far
+ */
+ Chromosome GetBestChromosome ();
+
+private:
+ /*!
+ * Create a chromosome that interconnect the list of nodes
+ * \fn Chromosome GenerateChromosome (std::vector<uint32_t> egressNodes)
+ * \param egressNodes The list of nodes that must be interconnected
+ * \return a randomly generated chromosome
+ */
+ Chromosome GenerateChromosome (std::vector<uint32_t> egressNodes);
+
+ /*!
+ * Remove all unnecessary path in the chromosome
+ * \fn void PruneChromosome (Chromosome &chromosome)
+ * \param chromosome The chromosome that will be pruned
+ */
+ void PruneChromosome (Chromosome &chromosome);
+
+ /*!
+ * Connect a node (node in the chromosome) to a node already present in the chromosome using a shortest path
+ * \fn void AddEqualCostShortestPath (Ptr<Node> egressToConnect, Ptr<Node> egressConnected, Chromosome &chromosome)
+ * \param egressToConnect The node to be connected
+ * \param egressConnected The node that is the target node
+ * \param chromosome The chromosome
+ */
+ void AddEqualCostShortestPath (Ptr<Node> egressToConnect, Ptr<Node> egressConnected, Chromosome &chromosome);
+
+ /*!
+ * Perform a crossover of chromosomes
+ * \fn std::pair<Chromosome, Chromosome> CrossOver (const Chromosome &chromosome1, const Chromosome &chromosome2)
+ * \param chromosome1 The first chromosome
+ * \param chromosome2 The other chromosome
+ * \return a pair of new chromosomes after the crossover
+ */
+ std::pair<Chromosome, Chromosome> CrossOver (const Chromosome &chromosome1, const Chromosome &chromosome2);
+
+ /*!
+ * Return the energy consumed by a chromosome
+ * double_t GetEnergy (const Chromosome &chromosome) const
+ * \param chromosome The chromosome
+ * \return the energy consumed by the chromosome
+ */
+ double_t GetEnergy (const Chromosome &chromosome) const;
+
+ std::vector<uint32_t> m_egressNodes; /*!< The list of nodes that must be interconnected */
+ double_t m_maxEnergy; /*!< The maximum energy that is conumed by the network */
+ double_t m_energyRouter; /*!< The energy consumed by a router's chassis */
+ double_t m_energyLineCard; /*!< The energy consumed by a router's line-card */
+
+ std::vector<Chromosome> m_population; /*!< The population of chromosome */
+
+ //Trace source: (idGeneration, avg fitness, best fitness, avg energy, best energy, max energy)
+ TracedCallback<uint32_t, double_t, double_t, double_t, double_t, double_t> m_generationTrace; /*!< Trace used when a new generation has been generated */
+
+};
+
+}} //namespace pgbr, ns3
+
+#endif /* GA_CORE_CALCULATOR_H_ */

Powered by Google App Engine
RSS Feeds Recent Issues | This issue
This is Rietveld f62528b