Documentation
¶
Index ¶
- Constants
- func BlankFitness(sd *SimDelays) float64
- func DistributionDistance(d1, d2 DelayDistribution) float64
- func RunGeneticAlgorithm(opcodes []string, config GeneticConfig, fitnessFunc FitnessFunc) (*SimDelays, *Population)
- type DelayDistribution
- type FitnessFunc
- type GeneticConfig
- type Individual
- type Population
- func (p *Population) EvaluatePopulation(fitnessFunc FitnessFunc)
- func (p *Population) Evolve(fitnessFunc FitnessFunc) *SimDelays
- func (p *Population) GetAverageFitness() float64
- func (p *Population) GetBest() *Individual
- func (p *Population) SelectParent(tournamentSize int) *Individual
- func (p *Population) SortByFitness()
- type Report
- type Rule
- type SimDelays
- type Simbox
Constants ¶
const ( TIMEC_ABS uint8 = 0 + iota // Rules in absolute time TIMEC_NONE // Rules with no temporal components TIMEC_REL // Relative time aka periodic TIMEC_ON_VALID // On valid signal TIMEC_ON_RECV // On receive signal TIMEC_ON_EXIT // When simulation ends )
const ( ACTION_SET uint8 = 0 + iota // Set a value to an object ACTION_GET // Get a value from an object ACTION_SHOW // Show a value from an object ACTION_CONFIG // Configuration directive )
Variables ¶
This section is empty.
Functions ¶
func BlankFitness ¶
BlankFitness is a placeholder fitness function that returns 0 This should be replaced with actual fitness evaluation logic
func DistributionDistance ¶
func DistributionDistance(d1, d2 DelayDistribution) float64
func RunGeneticAlgorithm ¶
func RunGeneticAlgorithm(opcodes []string, config GeneticConfig, fitnessFunc FitnessFunc) (*SimDelays, *Population)
RunGeneticAlgorithm is a convenience function to run the genetic algorithm with the given opcodes, configuration, and fitness function
Types ¶
type DelayDistribution ¶
func (*DelayDistribution) GetValue ¶
func (d *DelayDistribution) GetValue() int32
func (*DelayDistribution) Normalize ¶
func (d *DelayDistribution) Normalize()
type FitnessFunc ¶
FitnessFunc is the function signature for fitness evaluation
type GeneticConfig ¶
type GeneticConfig struct {
Debug bool // Enable debug output
PopulationSize int // Number of individuals in the population
Generations int // Number of generations to evolve
MutationRate float64 // Probability of mutation (0.0 to 1.0)
CrossoverRate float64 // Probability of crossover (0.0 to 1.0)
ElitismCount int // Number of best individuals to preserve
MinDelay int32 // Minimum delay value for distributions
MaxDelay int32 // Maximum delay value for distributions
DistributionSize int // Number of delay entries per distribution
}
GeneticConfig holds configuration for the genetic algorithm
func GetDefaultGeneticConfig ¶
func GetDefaultGeneticConfig() GeneticConfig
func GetGeneticConfigFromJSON ¶
func GetGeneticConfigFromJSON(fileName string) (GeneticConfig, error)
func (*GeneticConfig) ToJSONFile ¶
func (gc *GeneticConfig) ToJSONFile(fileName string) error
type Individual ¶
Individual represents a single solution in the population
type Population ¶
type Population struct {
Individuals []*Individual
Config GeneticConfig
Opcodes []string
}
Population represents a collection of individuals
func NewPopulation ¶
func NewPopulation(opcodes []string, config GeneticConfig) *Population
NewPopulation creates a new population with random individuals
func (*Population) EvaluatePopulation ¶
func (p *Population) EvaluatePopulation(fitnessFunc FitnessFunc)
EvaluatePopulation evaluates the fitness of all individuals in the population
func (*Population) Evolve ¶
func (p *Population) Evolve(fitnessFunc FitnessFunc) *SimDelays
Evolve runs the genetic algorithm for the configured number of generations
func (*Population) GetAverageFitness ¶
func (p *Population) GetAverageFitness() float64
GetAverageFitness returns the average fitness of the population
func (*Population) GetBest ¶
func (p *Population) GetBest() *Individual
GetBest returns the best individual in the population
func (*Population) SelectParent ¶
func (p *Population) SelectParent(tournamentSize int) *Individual
SelectParent performs tournament selection to choose a parent
func (*Population) SortByFitness ¶
func (p *Population) SortByFitness()
SortByFitness sorts the population by fitness in descending order (best first)
type Rule ¶
type Rule struct {
Timec uint8 // Time constraint type: absolute, relative, none, on valid, on receive
Tick uint64 // Tick (if applicable)
Action uint8 // Action: set, get, show, config
Object string // Object: register, memory, io, config option
Extra string // Extra info: unsigned, signed, hex, etc.
Suspended bool // Whether the rule is suspended
}
type SimDelays ¶
type SimDelays struct {
OpcodeDelays map[string]DelayDistribution // json:"opcode_delays"`
}
func LoadSimDelaysFromFile ¶
func MergeSimDelays ¶
func NewSimDelays ¶
func NewSimDelays() *SimDelays
func (*SimDelays) Crossover ¶
func (sd *SimDelays) Crossover(other *SimDelays, config GeneticConfig) *SimDelays
Crossover performs crossover between two SimDelays and returns a new offspring
func (*SimDelays) Mutate ¶
func (sd *SimDelays) Mutate(config GeneticConfig)
Mutate performs mutation on a SimDelays