📄 graph.h
字号:
// -*- C++ -*-
// Copyright (C) 2003 Leherstuh f黵 Betrieb System/ Verteilte System,
// Universitaet Dortmund
//
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License
// as published by the Free Software Foundation; either version 2
// of the License, or (at your option) any later version.
//
// 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: Muddassar Farooq
// Informatik III, Universitaet Dortmund
// Germany
//-------------------------------------------------------------
// file: graph.h
// (part of AntNet Routing Simulation)
//-------------------------------------------------------------
#ifndef __GRAPH_H
#define __GRAPH_H
#include <iostream>
#include <vector>
#include <omnetpp.h>
using namespace std;
struct routerNode
{
int nodeID;
routerNode(int address);
routerNode();
bool operator==(const routerNode rhs);
routerNode& operator = (const routerNode & rNode);
};
struct graphNode
{
struct routerNode node;
struct graphNode *nextGraphNode;
struct linkNode *outLinkNodeList;
struct linkNode *inLinkNodeList;
graphNode();
graphNode(routerNode node);
bool operator==(const graphNode& rhs);
bool operator!=(const graphNode& rhs);
};
struct linkNode
{
float linkCost;
struct graphNode *sourceNode;
struct graphNode *destNode;
struct linkNode *sameSourceNode;
struct linkNode *sameDestNode;
linkNode();
linkNode(graphNode *sourceNode, graphNode *destNode);
linkNode(linkNode &rhs);
linkNode(float linkDelayCost, graphNode *sourceNode, graphNode *dest);
bool operator==(const linkNode& rhs);
bool operator!=(const linkNode& rhs);
};
typedef struct graphNode graphNode;
typedef struct linkNode linkNode;
typedef pair<routerNode,float> destValue;
class graphNetwork: public cObject
{
friend ostream& operator<<(ostream& os, graphNetwork& graph);
private:
graphNode *listOfGraphNodes;
int numNodes;
int maxAddress;
public:
graphNetwork(const char *name = NULL);
graphNetwork(const graphNetwork& rhs);
virtual ~graphNetwork();
graphNetwork& operator= (const graphNetwork& rhs);
virtual cObject* dup() const;
virtual void info(char *buf);
virtual void writeContents(ostream& os);
void initializeGraph(char *name);
void addRouterNode(routerNode *rNode);
void deleteRouterNode(routerNode *rNode);
void addLink(routerNode *sourceRouter, routerNode *destRouter, float linkCost);
void updateLink(routerNode *sourceRouter, routerNode *destRouter, float linkCost);
void deleteLink(routerNode *sourceRouter, routerNode *destRouter);
bool linkExists(routerNode *sourceRouter, routerNode *destRouter);
bool routerExists(routerNode *rNode);
bool allOutAndInLinksDeleted(graphNode *source);
bool allOutLinksDoNotExist(routerNode *source);
bool allInLinksDoNotExist(routerNode *source);
int getSuccessrNodes(routerNode *rNode, vector<destValue> &adjacencyList);
routerNode getGraphNodeAtIndex(int i);
int getNumNodes();
int getMaxAddress();
private:
void addGraphNode(graphNode *node);
void deleteGraphNode(graphNode *node);
bool graphNodeExists(graphNode *node, graphNode **nodePtr);
bool linkNodeExists(linkNode *node, linkNode *list,
linkNode **nodePtr, bool outlist);
void addLinkNode(graphNode *source, graphNode *dest, linkNode *current);
void updateLinkNode(graphNode *source, graphNode *dest, linkNode *link);
void deleteLinkNode(linkNode *current);
public:
graphNode* getListOfGraphNodes();
};
#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -