lsystem

package module
v0.0.0-...-1eaf64c Latest Latest
Warning

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

Go to latest
Published: Feb 8, 2024 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ParseRules

func ParseRules(rulesMap map[Token]string) (TokenSet, TokenSet, map[Token]ProductionRule)

Types

type Buffer

type Buffer struct {
	BytePairs []TokenStateId
	Len       int
	Cap       int
}

func (*Buffer) Append

func (m *Buffer) Append(bp TokenStateId)

func (*Buffer) AppendSlice

func (m *Buffer) AppendSlice(bps []TokenStateId)

func (*Buffer) Grow

func (m *Buffer) Grow(atLeast int)

type ByteProductionRule

type ByteProductionRule struct {
	Weights           []ByteWeightedRule
	PreSampledWeights []uint8

	Predecessor TokenStateId
	// contains filtered or unexported fields
}

func (*ByteProductionRule) ChooseSuccessor

func (bp *ByteProductionRule) ChooseSuccessor(l *LSystem, previousToken TokenStateId) []TokenStateId

func (*ByteProductionRule) PreSample

func (bp *ByteProductionRule) PreSample()

func (*ByteProductionRule) RandomizeWeights

func (bp *ByteProductionRule) RandomizeWeights(delta float64, presample bool)

func (*ByteProductionRule) String

func (bp *ByteProductionRule) String(tokens [255]Token) string

type ByteWeightedRule

type ByteWeightedRule struct {
	LowerLimit float64
	UpperLimit float64
	Catalyst   TokenStateId
	Successor  []TokenStateId
}

type LSystem

type LSystem struct {
	Axiom     Token
	Rules     map[Token]ProductionRule
	Variables TokenSet
	Constants TokenSet

	EmptyTokenId TokenStateId
	TokenBytes   map[Token]TokenStateId
	BytesToken   [255]Token
	ByteRules    [255]ByteProductionRule
	ParamToByte  [255]TokenStateId

	Params  [128]uint8
	MemPool *MemPool
	// contains filtered or unexported fields
}

func NewLSystem

func NewLSystem(axiom Token, rulesMap map[Token]ProductionRule, vars TokenSet, consts TokenSet, useWeightPreSampling bool) *LSystem

func (*LSystem) AnalyseProductionRates

func (l *LSystem) AnalyseProductionRates() map[Token]ProductionRate

AnalyseProductionRates analyses the production rate of each production rule by creating a new LSystem for each rule containing only its own rules and itself as axiom. Then it iterates the LSystem for a given number of iterations and analyzing the distribution of the produced tokens.

func (*LSystem) DecodeBytes

func (l *LSystem) DecodeBytes(bp []TokenStateId) []Token

func (*LSystem) EncodeTokens

func (l *LSystem) EncodeTokens(tokens []Token) []TokenStateId

func (*LSystem) HandleStatisticsServer

func (l *LSystem) HandleStatisticsServer(w http.ResponseWriter, _ *http.Request)

func (*LSystem) IsConstant

func (l *LSystem) IsConstant(t Token) bool

func (*LSystem) IsVariable

func (l *LSystem) IsVariable(t Token) bool

func (*LSystem) Iterate

func (l *LSystem) Iterate(n int) []TokenStateId

func (*LSystem) IterateOnce

func (l *LSystem) IterateOnce() []TokenStateId

func (*LSystem) IterateUntil

func (l *LSystem) IterateUntil(n int) []TokenStateId

func (*LSystem) Recreate

func (l *LSystem) Recreate(byteRules [255]ByteProductionRule) *LSystem

func (*LSystem) RecreateWithMemPool

func (l *LSystem) RecreateWithMemPool(byteRules [255]ByteProductionRule, pool *MemPool) *LSystem

func (*LSystem) Reset

func (l *LSystem) Reset()

func (*LSystem) Serve

func (l *LSystem) Serve() error

func (*LSystem) String

func (l *LSystem) String() string

type MemPool

type MemPool struct {
	// contains filtered or unexported fields
}

func NewMemPool

func NewMemPool(capacity int) *MemPool

func (*MemPool) GetReadBuffer

func (m *MemPool) GetReadBuffer(idx int) *Buffer

func (*MemPool) GetWriteBuffer

func (m *MemPool) GetWriteBuffer(idx int) *Buffer

func (*MemPool) ReadAll

func (m *MemPool) ReadAll() []TokenStateId

func (*MemPool) Reset

func (m *MemPool) Reset()

func (*MemPool) Swap

func (m *MemPool) Swap(idx int)

func (*MemPool) SwapAll

func (m *MemPool) SwapAll()

type ProductionRate

type ProductionRate struct {
	Token Token
	Rates []float32
	Rule  fmt.Stringer
}

func (*ProductionRate) RenderChart

func (pr *ProductionRate) RenderChart(w io.Writer) error

type ProductionRule

type ProductionRule struct {
	Predecessor Token
	Weights     []WeightedRule
}

func NewProductionRule

func NewProductionRule(predecessor Token, weights []WeightedRule) ProductionRule

func (*ProductionRule) ChooseSuccessor

func (r *ProductionRule) ChooseSuccessor() []Token

func (*ProductionRule) EncodeTokens

func (r *ProductionRule) EncodeTokens(tokenBytes map[Token]TokenStateId, presample bool) ByteProductionRule

func (*ProductionRule) String

func (r *ProductionRule) String() string

type Token

type Token string

func ParseState

func ParseState(state string) []Token

type TokenSet

type TokenSet map[Token]struct{}

func (TokenSet) Add

func (ts TokenSet) Add(t Token)

func (TokenSet) AsSlice

func (ts TokenSet) AsSlice() []Token

func (TokenSet) Contains

func (ts TokenSet) Contains(t Token) bool

type TokenStateId

type TokenStateId uint8

func NewTokenStateId

func NewTokenStateId(tokenId uint8, hasParam bool) TokenStateId

func (TokenStateId) HasParam

func (bt TokenStateId) HasParam() bool

func (TokenStateId) TokenId

func (bt TokenStateId) TokenId() uint8

type WeightedRule

type WeightedRule struct {
	Probability float64
	Catalyst    Token
	Tokens      []Token
}

func ParseRule

func ParseRule(str string) []WeightedRule

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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