-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
csp - initial algorithm and new test dlg
- Loading branch information
1 parent
3e7a0e5
commit f605557
Showing
10 changed files
with
222 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,3 +8,4 @@ | |
*.sdf | ||
*.suo | ||
*.aps | ||
*.user |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,7 +6,7 @@ | |
|
||
namespace Problems | ||
{ | ||
namespace BPP | ||
namespace CSP | ||
{ | ||
|
||
Point& Point::operator =(const Point& rhs) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,7 +8,7 @@ | |
|
||
namespace Problems | ||
{ | ||
namespace BPP | ||
namespace CSP | ||
{ | ||
|
||
class Size; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
|
||
#include "CSPAlgorithm.h" | ||
|
||
CSPAlgorithm::CSPAlgorithm(Common::Observing::GaEventHandler* handler) : _populationFitnessOperation(&_fitnessOperation), | ||
_workflow(NULL) | ||
{ | ||
GaInitialize(); | ||
|
||
Chromosome::GaMatingConfig matingConfiguration( | ||
Chromosome::GaCrossoverSetup( &_crossover, &Chromosome::GaCrossoverParams( 1.0f, 2 ), NULL ), | ||
Chromosome::GaMutationSetup( &_mutation, &Chromosome::GaMutationSizeParams( 0.66f, true, 2L ), NULL ) ); | ||
|
||
Fitness::GaFitnessComparatorSetup fitnessComparatorSetup( &_fitnessComparator, | ||
&Fitness::Comparators::GaSimpleComparatorParams( Fitness::Comparators::GACT_MAXIMIZE_ALL ), NULL ); | ||
|
||
Algorithm::Stubs::GaSimpleGAStub::GaStatTrackersCollection trackers; | ||
trackers[ Population::GaPopulationSizeTracker::TRACKER_ID ] = &_sizeTracker; | ||
trackers[ Population::GaRawFitnessTracker::TRACKER_ID ] = &_rawTracker; | ||
trackers[ Population::GaScaledFitnessTracker::TRACKER_ID ] = &_scaledTracker; | ||
|
||
Population::GaSelectionSetup selectionSetup( &_selection, | ||
&Population::SelectionOperations::GaTournamentSelectionParams( 2, -1, 2, 2, Population::SelectionOperations::GaTournamentSelectionParams::GATST_ROULETTE_WHEEL_SELECTION ), | ||
&Population::SelectionOperations::GaTournamentSelectionConfig( fitnessComparatorSetup, Chromosome::GaMatingSetup() ) ); | ||
|
||
Population::GaCouplingSetup couplingSetup( &_coupling, &Population::GaCouplingParams( 50, 1 ), | ||
&Population::GaCouplingConfig( Chromosome::GaMatingSetup( &_mating, NULL, &matingConfiguration ) ) ); | ||
|
||
Population::GaReplacementSetup replacementSetup( &_replacement, &Population::GaReplacementParams( 50 ), &Population::GaReplacementConfig() ); | ||
Population::GaScalingSetup scalingSetup( &_scaling, NULL, &Population::GaScalingConfig() ); | ||
|
||
Algorithm::Stubs::GaSimpleGAStub simpleGA( WDID_POPULATION, WDID_POPULATION_STATS, | ||
Chromosome::GaInitializatorSetup(), | ||
Population::GaPopulationFitnessOperationSetup( &_populationFitnessOperation, NULL, | ||
&Fitness::GaFitnessOperationConfig( NULL ) ), | ||
fitnessComparatorSetup, | ||
Population::GaPopulationParams( 100, 0, Population::GaPopulationParams::GAPFO_FILL_ON_INIT ), | ||
trackers, | ||
Chromosome::GaMatingSetup(), | ||
selectionSetup, | ||
couplingSetup, | ||
replacementSetup, | ||
scalingSetup, | ||
Population::GaFitnessComparatorSortingCriteria( fitnessComparatorSetup, Population::GaChromosomeStorage::GAFT_RAW ) ); | ||
simpleGA.SetBranchCount( 2 ); | ||
|
||
_workflow.RemoveConnection( *_workflow.GetFirstStep()->GetOutboundConnections().begin(), true ); | ||
|
||
Common::Workflows::GaWorkflowBarrier* br1 = new Common::Workflows::GaWorkflowBarrier(); | ||
simpleGA.Connect( _workflow.GetFirstStep(), br1 ); | ||
|
||
Common::Workflows::GaBranchGroup* bg1 = (Common::Workflows::GaBranchGroup*)_workflow.ConnectSteps( br1, _workflow.GetLastStep(), 0 ); | ||
|
||
Algorithm::StopCriteria::GaStopCriterionStep* stopStep = new Algorithm::StopCriteria::GaStopCriterionStep( | ||
Algorithm::StopCriteria::GaStopCriterionSetup( &_stopCriterion, | ||
&Algorithm::StopCriteria::GaStatsChangesCriterionParams( | ||
Population::GADV_BEST_FITNESS, 100), NULL ), _workflow.GetWorkflowData(), WDID_POPULATION_STATS ); | ||
|
||
Common::Workflows::GaBranchGroupTransition* bt1 = new Common::Workflows::GaBranchGroupTransition(); | ||
|
||
bg1->GetBranchGroupFlow()->SetFirstStep( stopStep ); | ||
bg1->GetBranchGroupFlow()->ConnectSteps( stopStep, bt1, 0 ); | ||
_workflow.ConnectSteps( bt1, simpleGA.GetStubFlow().GetFirstStep(), 1 ); | ||
|
||
Common::Workflows::GaDataCache<Population::GaPopulation> population( _workflow.GetWorkflowData(), WDID_POPULATION ); | ||
|
||
population.GetData().GetEventManager().AddEventHandler( Population::GaPopulation::GAPE_NEW_GENERATION, handler ); | ||
} | ||
|
||
CSPAlgorithm::~CSPAlgorithm() | ||
{ | ||
_workflow.Wait(); | ||
|
||
GaFinalize(); | ||
} | ||
|
||
void CSPAlgorithm::SetParameters(int sWidth, int sHeight, int iMinWidth, int iMaxWidth, int iMinHeight, int iMaxHeight, int iCount) | ||
{ | ||
Common::Data::GaSingleDimensionArray<Problems::CSP::Item> items( iCount ); | ||
for( int i = 0; i < iCount; i++ ) | ||
items[ i ] = Problems::CSP::Item( | ||
Problems::CSP::Size(GaGlobalRandomFloatGenerator->Generate( iMinWidth, iMaxWidth ), GaGlobalRandomFloatGenerator->Generate( iMinHeight, iMaxHeight ) ), | ||
std::string( "L" ), i ); | ||
|
||
Chromosome::GaInitializatorSetup initializatorSetup( &_initializator, NULL, &Chromosome::GaInitializatorConfig( | ||
&Problems::CSP::CspConfigBlock( items, Problems::CSP::Size( sWidth, sHeight ) ) ) ); | ||
|
||
Common::Workflows::GaDataCache<Population::GaPopulation> population( _workflow.GetWorkflowData(), WDID_POPULATION ); | ||
population.GetData().SetInitializator( initializatorSetup ); | ||
} | ||
|
||
void CSPAlgorithm::Start() | ||
{ | ||
_workflow.Start(); | ||
} | ||
|
||
void CSPAlgorithm::Stop() | ||
{ | ||
_workflow.Stop(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
|
||
#pragma once | ||
|
||
#include "..\..\source\Initialization.h" | ||
#include "..\..\Problems\CSP.h" | ||
#include "..\..\source\Crossovers.h" | ||
#include "..\..\source\SimpleStub.h" | ||
#include "..\..\source\Matings.h" | ||
#include "..\..\source\PopulationStatistics.h" | ||
#include "..\..\source\StopCriteria.h" | ||
|
||
#include "..\..\source\Selections.h" | ||
#include "..\..\source\Couplings.h" | ||
#include "..\..\source\Replacements.h" | ||
#include "..\..\source\FitnessSharing.h" | ||
#include "..\..\source\Scalings.h" | ||
#include "..\..\source\StopCriteria.h" | ||
|
||
class CSPAlgorithm | ||
{ | ||
private: | ||
enum WorkflowDataIDs | ||
{ | ||
WDID_POPULATION, | ||
WDID_POPULATION_STATS | ||
}; | ||
|
||
Problems::CSP::CspInitializator _initializator; | ||
Problems::CSP::CspCrossoverOperation _crossover; | ||
Problems::CSP::CspMutationOperation _mutation; | ||
Problems::CSP::CspFitnessOperation _fitnessOperation; | ||
Fitness::Comparators::GaSimpleComparator _fitnessComparator; | ||
|
||
Population::GaCombinedFitnessOperation _populationFitnessOperation; | ||
|
||
Chromosome::MatingOperations::GaBasicMatingOperation _mating; | ||
|
||
Population::GaPopulationSizeTracker _sizeTracker; | ||
Population::GaRawFitnessTracker _rawTracker; | ||
Population::GaScaledFitnessTracker _scaledTracker; | ||
|
||
Population::SelectionOperations::GaTournamentSelection _selection; | ||
Population::CouplingOperations::GaSimpleCoupling _coupling; | ||
Population::ReplacementOperations::GaWorstReplacement _replacement; | ||
Population::ScalingOperations::GaNoScaling _scaling; | ||
|
||
Algorithm::StopCriteria::GaStatsChangesCriterion _stopCriterion; | ||
|
||
Common::Workflows::GaWorkflow _workflow; | ||
|
||
|
||
public: | ||
CSPAlgorithm(Common::Observing::GaEventHandler* handler); | ||
~CSPAlgorithm(); | ||
|
||
void SetParameters(int sWidth, int sHeight, int iMinWidth, int iMaxWidth, int iMinHeight, int iMaxHeight, int iCount); | ||
|
||
void Start(); | ||
void Stop(); | ||
|
||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters