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

zhaozj2021-02-16  44

// File geneSet.h

#pragma overce

#include "routgene.h"

Class GeneSet

{

PUBLIC:

GENESET (int _nodenum, int ** & _ netArray, int ** & _ valarray);

~ Geneset (void);

Void AddRear (ROUTGENE & Ge);

ROUTGENE & FIRST (VOID);

Void Removefirst (Void);

Void sort (void);

RoutGene & GetBest (Void);

Void Removehalf (Void);

int REAR (VOID);

Void Removeall (Void);

Private:

Routgene geneArray [max_gene_number];

IntR;

INT NODENUM;

Int ** & netArray;

Int ** & valarray;

Private:

/ / Calculate the length of the genes

INT DISTANES (ROUTGENE & Ge);

// Calculate the smallest length from II to JJ routing

Int mingene (INT II, ​​INT JJ);

}

// File geneSet.cpp

#include "geneset.h"

#using

#include "resource.h"

Using Namespace GeneResource;

GENESET :: GENESET (int _nodenum, int **& _ netARRAY, INT **)

: NetArray (_NetArray), Valarray (_Valarray)

{

Nodenum = _Nodenum;

For (int i = 0; i

GeneArray [i] .Setnodenum (nodenum);

REAR = 0;

}

GeneSet :: ~ GENESET (VOID)

{

}

Void GeneSet :: AddRear (Routgene & Ge)

{

IF (REAR

{

GENEARRAY [REAR] = Gene;

REAR ;

}

}

ROUTGENE & GENESET :: First (void)

{

// Todo: Return Statement

Return GeneArray [0];

}

Void GeneSet :: Removefirst (Void)

{

For (int i = 0; i

GeneArray [i] = geneArray [i 1];

IF (REAR> = 1)

{

GeneArray [Rear-1] .Setnodenum (NodeNum);

REAR -;

}

}

Void GeneSet :: Sort (void)

{// Sort Gene

RoutGene Gene = GeneArray [0];

INT min = 0;

For (int i = 0; i

{

Min = minnene (i, rear-1);

IF (i! = min)

{

Gene = GeneArray [i];

GeneArray [i] = geneArray [min];

GENEARRAY [min] = gene;

}

}

}

RoutGene & GeneSet :: getBest (void) {// call back after Sort

// Todo: Return Statement

Return GeneArray [0];

}

Void GeneSet :: Removehalf (void)

{

IF (REAR / 2> 0)

{

For (int I = Rear / 2; i

GeneArray [i] .Setnodenum (nodenum);

REAR = Rear / 2;

}

}

Void GeneSet :: Removeall (Void)

{

While (Rear> 0)

{

GeneArray [Rear-1] .Setnodenum (NodeNum);

- REAR;

}

}

Int GeneSet :: Rear (Void)

{

Return REAR;

}

INT GeneSet :: Distance (Routgene & Ge)

{// Calculate the length of the road in Gene

NodeSet NodeSet = Node (Gene);

Int max = nodset.getlastindex ();

INT distance = 0, ROW = 0, COL = 0;

For (int i = 0; i

{

ROW = * (NodeSet.getPNode () i);

COL = * (NodeSet.GetPNodeEt () i 1);

Distance = Valarray [ROW] [col];

}

Return distance;

}

Int GeneSet :: MINGENE (Int II, INT JJ)

{

//REAR> JJ> = ii> = 0

Routgene gene = geneArray [ii];

Int results = II;

For (int i = II; i <= jj; i )

{

IF (Distance (Gene)> Distance (GeneArray [i]))

{

Gene = GeneArray [i];

Result = i;

}

}

Return Result;

}

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

New Post(0)