Routing Simulation - Realization of Routing Algorithm 1 (Routing Calculation Class 2)

zhaozj2021-02-16  54

/* Parameter Description:

_NetArray: Routnum * Routnum matrix, network topology information

_Valarray: Routnum * Routnum matrix, network dissipation information

Result: RoutNum * 2 matrix, routing table - return

_ROUTNUM: Number of routers

Index: Source Routor

* / void routcompute :: computemethods (int ** _netArray, int ** _Valarray,

Int ** & result, int _routnum, int index

{

//initialization

INIT (_NetArray, _Valarray, _Routnum);

// initialization of local variables

GENESET HALFGENESET (NodeNum, NetArray, Valarray);

GeneSet Bestgeneset (NodeNum, NetArray, Valarray);

ROUTGENE Gene (Nodenum);

ROUTGENE BEST (NODENUM);

Int T;

For (int to = 0; to

{// calculate index to to routing table

T = 0;

Pgeneset-> removeall ();

While (t

{// maximum evolution MAX_T generation

While (pgeneset-> rest ()

{

Gene.init (INDEX, TO);

While (True)

{/ gene growth process

Builder (Gene);

// If Gene is no longer a complete route

IF (Decomplete (Gene))

RandomDelete (Gene);

// If Gene is a complete route

COMPLETE (Gene))

Break;

} // end of while

// Add Gene to a mature Gene collection

Pgeneset-> addRear (gene);

} // end of while

Pgeneset-> sort ();

BEST = pgeneset-> getBest ();

BestgeneSet.Addrear (BEST);

//

Pgeneset-> Removehalf ();

/ * The annotation portion is the initial design of the algorithm, and further evolving the remaining Gene.

But here is temporarily not designed, but only half of the Gene is directly entering the next generation of competition.

While (pgeneset-> rest ()> 0)

{

Gene = pgeneset-> first ();

// Gene Evolution

Evolution (Gene);

Halfgeneset.addrear (Gene);

Pgeneset-> removefirst ();

}

While (Halfgeneset.Rear ()> 0)

{

Gene = Halfgeneset.first ();

Halfgeneset.RemoveFirst ();

Pgeneset-> addRear (gene);

} * /

// Evolution Algebra

T ;

} // end of while (true)

BESTGENESET.SORT ();

Best = bestgeneset.getBest ();

BESTGENESET.RemoveAll ();

// Fill the routing table

Result [to] [0] = TO;

Result [to] [1] = * (Node (Best) .getpnodeset () 1);

}

}

Void RoutCompute :: evolution (routgene & gene)

{// Gene's evolution is not designed

}

Bool RoutCompute :: Complete (Routgene & Ge)

{// Judgment does Gene is a complete route

NodeSet GENENODES = NODE (Gene);

Bool bval = true;

Int M, N;

INT index = gnenodes.getlastindex ();

IF (INDEX! = -1)

{

For (INT i = 0; i

{

m = * (gENENODES.GETPNODESET () i);

n = * (gENENODES.GETPNODESET () i 1);

BVAL = BVAL && (NetArray [M] [N] == 1);

} // End of for

Return BVAL;

} // end of if

Return False;

}

Bool RoutCompute :: Decomplete (Routgene & Ge)

{// Judging whether the genene is impossible to become a complete route

Bool Bval = Complete (Gene);

NodeSet GENENODES = NODE (Gene);

NodeSet_Genenodes = routnodes - GENENODES;

INT INDEX = _GENENODES.GetlastIndex ();

IF (! BVAL && Index == - 1)

Return True;

Return False;

}

Void RoutCompute :: Builder1 (Routgene & Ge)

{// conservative growth

NodeSet GENENODES = NODE (Gene);

NodeSet nextNodes (NodeNum);

Int value, index = gENENODES.GetLastIndex ();

INT K = 0, NewNode;

IF (INDEX> 0)

{

Value = * (gENENODES.GETPNODESET () INDEX-1);

For (int i = 0; i

IF (NetArray [Value] [i] == 1)

* (NextNodes.getPNODESET () K ) = i;

NexTnodes = nextnodes - GENENODES;

NewNode = Random (NextNodes);

IF (newNode! = -1)

Gene.incRease (newNode);

}

}

Void RoutCompute :: Builder2 (Routgene & Ge)

{// Open

NodeSet GENENODES = NODE (Gene);

NodeSet_Genenodes = routnodes - GENENODES;

INT new = random (_GENENODES);

IF (newNode! = -1)

Gene.incRease (newNode);

}

Void RoutCompute :: Builder (Routgene & Ge)

{/ Raise method

Double P = ((Double) Randinteger (1000)) / 1000.0;

IF (P

BUILDER1 (Gene);

Else

Builder2 (Gene);

}

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

New Post(0)