simbox

package
v0.0.0-...-51e0ef3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 6, 2026 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Index

Constants

View Source
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
)
View Source
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

func BlankFitness(sd *SimDelays) float64

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

type DelayDistribution map[int32]float32 // map of delay in clocks to probability

func (*DelayDistribution) GetValue

func (d *DelayDistribution) GetValue() int32

func (*DelayDistribution) Normalize

func (d *DelayDistribution) Normalize()

type FitnessFunc

type FitnessFunc func(*SimDelays) float64

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

type Individual struct {
	SimDelays *SimDelays
	Fitness   float64
}

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 Report

type Report struct {
}

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
}

func (Rule) String

func (rule Rule) String() string

type SimDelays

type SimDelays struct {
	OpcodeDelays map[string]DelayDistribution // json:"opcode_delays"`
}

func LoadSimDelaysFromFile

func LoadSimDelaysFromFile(filename string) (*SimDelays, error)

func MergeSimDelays

func MergeSimDelays(sdPrimary, sdSecondary *SimDelays) *SimDelays

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

type Simbox

type Simbox struct {
	Rules []Rule
}

func (*Simbox) Add

func (r *Simbox) Add(adds string) error

func (*Simbox) Del

func (r *Simbox) Del(idx int) error

func (*Simbox) Print

func (r *Simbox) Print() string

func (*Simbox) Reactivate

func (r *Simbox) Reactivate(idx int) error

func (*Simbox) Suspend

func (r *Simbox) Suspend(idx int) error

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL