home *** CD-ROM | disk | FTP | other *** search
Text File | 1997-07-16 | 4.7 KB | 167 lines | [TEXT/CWIE] |
- // ===========================================================================
- // CGraphDrawing.h ©1995-97 Timo Eloranta All rights reserved.
- // ===========================================================================
- // An instance of the CGraphDrawing class represents a single possibility of
- // drawing the given graph. The population consists of these objects.
-
- #pragma once
-
- #include <PP_Constants.h>
-
- #include "CEdge.h"
- #include "CFitness.h"
- #include "CGraphNodes.h"
- #include "MyStructs.h"
-
- #include <vector.h> // MSL
- #include <iterator.h> // MSL
-
- typedef CGraphDrawing* CGraphPtr;
- typedef vector<CEdge, allocator<CEdge> > EdgeVector;
-
- class CCrossMemory;
-
- class CGraphDrawing
- {
- private:
- Int16 mEdgeCount;
- Int16 mSelectionOriginal;
- Boolean mEvaluationNeeded;
- Boolean mMemoryIsGarbage;
- CFitness mFitness;
-
- CGraphNodes mNodes; // My nodes storage
- EdgeVector mEdges; // My array of edges
-
- CCrossMemory *mCrossMemo; // Structure which holds the
- // info on edge crossings
-
- Boolean EdgeMutation( Boolean inPreserveLength, Boolean inTiny );
- Boolean TwoEdgeMutation();
-
- void Evaluate( Int32 inCurLeastCrossings );
-
- Int32 SimpleCountSect();
- Int32 SmarterCountSect();
- void CountEdgeLengths();
- void CopyEdges( const CGraphDrawing & inGD);
-
- Boolean ThreeConnectedNodes( CNodePtr &outNode1,
- CNodePtr &outNode2,
- CNodePtr &outNode3 );
-
- public:
- CGraphDrawing();
- ~CGraphDrawing();
-
- void Initialize( Int16 inNodeCount,
- Int16 inEdgeCount,
- Int16 inGridSize,
- Boolean inFirstTime);
-
- void AddCrossMemory();
- void JunkCrossMemory();
-
- Boolean ValidNewEdge( Int16 inNodeNbr1,
- Int16 inNodeNbr2) const;
-
- void SetNewEdge( Int16 inEdgeNbr,
- Int16 inNodeNbr1,
- Int16 inNodeNbr2);
-
- void Mutate();
- void RectCrossover( const Rect &inSourceRect,
- const Rect &inDestRect,
- const CGraphDrawing &inBaseGraph,
- const CGraphDrawing &inRectGraph );
- void ThreeNodeCrossover( CGraphPtr inCrosser2 );
-
- void GetFitness( CFitness &outFitness,
- Int32 inCurLeastCrossings = max_Int32 );
-
- Int16 GetGridSize( ) const
- { return mNodes.GetGridSize(); };
-
- CGraphNodes * GetNodes( ) const
- { return (CGraphNodes *) &mNodes; };
-
- void SetSelectionOriginal( Int16 inGraphNbr )
- { mSelectionOriginal = inGraphNbr; };
-
- Int16 GetSelectionOriginal( ) const
- { return mSelectionOriginal; };
-
- void DrawEdges( Int16 inOneOneXY,
- Int16 inSquareSize) const;
- void DrawNodes( const Rect & inOneOneRect,
- Int16 inSquareSize) const;
-
- void BestCopy( const CGraphDrawing & inGD,
- Boolean inFirstTime );
- void RuntimeCopy( const CGraphDrawing & inGD,
- Boolean inCopyCrossMemory );
-
- Boolean operator==( const CGraphDrawing & inGD) const
- { return ( mFitness == inGD.mFitness ); };
- Boolean operator<( const CGraphDrawing & inGD) const
- { return ( mFitness < inGD.mFitness ); };
- };
-
- struct SGraphPtrComparator {
- Boolean operator()( const CGraphPtr& in1st,
- const CGraphPtr& in2nd ) {
- return (*in1st) < (*in2nd);
- }
- };
-
- null_template
- struct iterator_trait <CGraphDrawing*const*> {
- typedef ptrdiff_t distance_type;
- typedef CGraphDrawing*const value_type;
- typedef random_access_iterator_tag iterator_category;
- };
-
- null_template
- struct iterator_trait <CGraphDrawing**> {
- typedef ptrdiff_t distance_type;
- typedef CGraphDrawing* value_type;
- typedef random_access_iterator_tag iterator_category;
- };
-
- // ===========================================================================
- // • Inline Functions
- // ===========================================================================
-
- // ---------------------------------------------------------------------------
- // • DrawNodes
- //
- // Called by: CGraphPane::DrawNodes
- // ---------------------------------------------------------------------------
-
- inline void
- CGraphDrawing::DrawNodes( const Rect &inOneOneRect, Int16 inSquareSize) const
- {
- mNodes.DrawAll( inOneOneRect, inSquareSize);
- }
-
- // ---------------------------------------------------------------------------
- // • GetFitness
- //
- // Called by: CPopulation::InitBestEver
- // CPopulation::Evaluate
- // CPopulation::GetBestEverFitness
- // ---------------------------------------------------------------------------
-
- inline void
- CGraphDrawing::GetFitness(
- CFitness &outFitness,
- Int32 inCurLeastCrossings )
- {
- // Evaluate only if necessary (if the chromosome has changed)
-
- if ( mEvaluationNeeded )
- Evaluate( inCurLeastCrossings );
-
- outFitness = mFitness;
- }
-