Routing Simulation - Realization of Routing Algorithm 1 (Non-point Collection)

zhaozj2021-02-16  43

// File NodeSet.h

#pragma overce

#include "resource.h"

Using Namespace GeneResource;

Class NodeSet

{

PUBLIC:

NodeSet (Void)

: nodenum (0)

NodeArray (NULL)

{

}

NodeSet (int _nodenum)

{

Nodenum = _Nodenum;

NodeArray = new int [gene_length];

For (int i = 0; i

NodeArray [i] = - 1;

}

NodeSet (NodeSet & _nodeset)

{

Nodenum = _nodeset.nodenum;

NodeArray = new int [gene_length];

For (int i = 0; i

NodeArray [i] = * (_ NodeSet.NodeArray i);

}

~ NodeSet (Void)

{

Clear ();

}

PUBLIC:

Void setnodenum (int _nodenum)

{

Clear ();

Nodenum = _Nodenum;

NodeArray = new int [gene_length];

For (int i = 0; i

NodeArray [i] = - 1; // empty collection

}

Void Clear (Void)

{

IF (NodeArray! = NULL)

DELETE [] NodeArray;

}

Int * & getpnodeset ()

{

Return NodeArray;

}

int GETNODENUM ()

{

Return nodenum;

}

Friend Int Random (NodeSet & _nodeset)

{

INT N = 0, MAX = 0;

Double P = 0.0;

For (int i = 0; i

IF (* (_ NodeSet.NodeArray i)! = -1)

MAX ;

//0.1 Probability selection failed

P = randinteger (1000);

IF (p / 1000> 0.9)

Return -1;

// Select the node

n = randinteger (max);

IF (_NodeSet.NodeArray! = null)

Return * (_ NodeSet.NodeArray N);

Else

Return -1;

}

// Get the label of the last node; return -1 is empty

Int getLastIndex ()

{

For (int i = 0; i

IF (* (NodeArray i) == -1)

RETURN I-1;

Return -1;

}

// Subtract from _nodeset1 and the node that appears in _nodeset2

Friend NodeSet & Operator - (NodeSet & _nodeSet1, NodeSet & _nodeset2)

{

// Todo: Return Statement

INT n = _nodeset1.nodenum;

INT K = 0;

Bool bval = true;

NodeSet * nodeset = new nodeset (n);

For (INT i = 0; i

For (int J = 0; j

IF (* (_ nodeset1.nodeaRray i)

== * (_ nodeset2.nodeArray J)))

{

BVAL = false;

Break;

}

IF (BVAL)

{

* (NodeSet-> NodeArray K) = * (_ NodeSet1.nodeArray i);

K ;

Else

BVAL = true;

}

Return * NodeSet;

}

Void Operator = (NodeSet & _nodeset)

{

IF (nodenum! = _ nodeset.nodenum)

SetNodenum (_NODESET.NODENUM);

For (int i = 0; i

* (NodeArray i) = * (_ NodeSet.NodeArray i);

}

Private:

INT NODENUM;

INT * NODEARRAY;

}

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

New Post(0)