Routing Simulation - Realization of Routing Algorithm 1 (Routing Gene)

zhaozj2021-02-16  45

// file routgene.h

#pragma overce

#include "nodset.h"

Class RoutGene

{

PUBLIC:

Routgene (int _nodenum = 0);

~ ROUTGENE (VOID);

PUBLIC:

Void setnodenum (int _nodenum);

Void Init (int from, int to);

// Gene increases Element fragment

Void Increase (int Element);

Void Operator = (RoutGene & Gene);

BOOL ismax ();

PUBLIC:

Friend NodeSet & Node (Routgene & Gene);

// Remove the clips in Gene

Friend void randomdelete (routgene & gene);

// Print: Test

Friend Void Print (RoutGene & Ge);

Private:

INT NODENUM;

Int last;

Node Colset GeneData;

}

// File RoutGene.cpp

#include "routgene.h"

#using

#include "resource.h"

#include

Using Namespace GeneResource;

Using namespace std;

Routgene :: Routgene (int _nodenum)

{

IF (_NodeNum <0)

{

COUT << "/ Nerror: The Node Number <0! / n / n";

EXIT (-1);

}

Nodenum = _Nodenum;

Last = 0;

GeneData.setnodenum (nodenum);

}

Routgene :: ~ Routgene (void)

{

}

Void RoutGene :: setNodenum (int _nodenum)

{

IF (_NodeNum <= 1)

{

COUT << "/ Nerror: The node number <= 1! / n / n";

EXIT (-1);

}

Nodenum = _Nodenum;

Last = 0;

GeneData.setnodenum (nodenum);

}

Void RoutGene :: Init (int from, int to)

{

Last = 0;

For (int i = 0; i

* (geneData.getpnodeset () i) = -1;

GeneData.getPnode ()) = from;

Last;

* (GeneData.getPNodeEt () Last) = TO;

}

Void RoutGene :: Increase (int element)

{// Gene increases Element fragment

IF (Last

{

* (GeneData.getPNodeEt () Last 1) = * (GeneData.getPNodeEt () Last);

* (geneData.getpnodeset () last) = element;

Last;

}

}

Void RoutGene :: Operator = (routgene & gene) {

Nodenum = gene.nodenum;

Last = gene.last;

Genedata = gene.genedata;

}

Bool routgene :: ismax ()

{

Return Last> = Gene_length-1;

}

NodeSet & Node (RoutGene & Gene)

{

// Todo: Return Statement

Return gene.geundata;

}

Void Randomdelete (RoutGene & Gene)

{// Random Delete Segment in Gene

Int randinteger;

Randinteger = randinteger (gene.last);

IF (gene.last-randinteger> = 1 && randinteger> 0) {

For (int i = 1; i

* (gene.GeneData.getpnodeset () gene.last-i) = -1;

* (Gene.GeneData.getPNodeSet () gene.last-randinteger) =

* (gene.genedata.getpnodeset () gene.last);

* (gene.GeneData.getPNodeSet () gene.last) = -1;

Gene.last - = randinteger;

}

}

Void Print (RoutGene & Ge)

{

COUT << "/ n / ngene: / n";

For (int i = 0; i <= gene.last; i )

Cout << * (Gene.GeNedata.getPNODESET () i);

Cout << "/ n / n";

}

转载请注明原文地址:https://www.9cbs.com/read-25377.html

New Post(0)