Documentation
¶
Overview ¶
Package config loads a model file into a variate.Graph and a variate.Config: YAML with one family key per distribution, time units converted to periods through the file's period declaration, several graphs merged under their names, and templates expanded into independent copies. The file is untrusted input: it is capped in size, walked as a node tree with every unknown key an error, and any data file it names must sit beside it.
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func SetSetting ¶
SetSetting assigns one run setting from its text form, as the file key (snake_case) or the flag name (kebab-case). Durations take Go syntax.
Example ¶
Settings arrive from the file or from flags; SetSetting takes either spelling.
package main
import (
"fmt"
"code.eitanity.com/variate"
"code.eitanity.com/variate/config"
)
func main() {
var cfg variate.Config
_ = config.SetSetting(&cfg, "min-hits", "500")
_ = config.SetSetting(&cfg, "tail", "0.99")
fmt.Println(cfg.MinHits, cfg.TailP)
}
Output: 500 0.99
Types ¶
type Block ¶
type Block struct {
Source string
Rate float64 // failures per period
MTBF float64 // hours between failures, downtime included
}
Block is a reliability diagram a source stands on: the stationary frequency of the system's failures, its MTBF and its unavailability, for independent components with exponential failure and repair times. The engine simulates the diagram's units exactly; these figures are its long-run mean.
type Model ¶
type Model struct {
Graph variate.Graph
Config variate.Config
PeriodHours float64
Blocks []Block // the sources whose rates came from reliability blocks
}
Model is a loaded file: the merged graph, the run settings it declares, and the period length in hours (0 when the file declares none).
func Load ¶
Load reads and parses a model file. Data files it names resolve relative to its directory.
func Parse ¶
Parse parses model text. dir is the directory data files resolve in; empty forbids them.
Example ¶
A model file: run settings at the top, then the graphs. Parse takes the text and the directory data files resolve in (empty: none).
package main
import (
"context"
"fmt"
"code.eitanity.com/variate/config"
)
func main() {
const text = `
periods: 10000
seed: 11
period: { days: 365 }
graphs:
- id: pumps
sources:
- { id: trip, frequency: { pert: [2, 5, 12] }, to: repair }
nodes:
- id: repair
functions:
- { name: callout, category: labour, pert: [500, 1200, 4000] }
outcomes:
- { to: replace, p: { beta: [2, 8] } }
- { to: done, holding: { pert: [1, 3, 10], unit: days } }
- id: replace
functions:
- { name: pump, category: capital, logpert: [2e4, 5e4, 2e5] }
- id: done
`
m, err := config.Parse([]byte(text), "")
if err != nil {
fmt.Println(err)
return
}
c, _, err := m.Graph.Compile(m.Config)
if err != nil {
fmt.Println(err)
return
}
e, _ := c.Analytic()
r, err := c.Simulate(context.Background(), m.Config)
if err != nil {
fmt.Println(err)
return
}
fmt.Printf("period %g hours periods %d exact mean %.0f\n", m.PeriodHours, r.Periods, e.Mean)
fmt.Printf("simulated mean within 5%% of exact: %v\n", within(r.Total.Mean(), e.Mean, 0.05*e.Mean))
}
func within(x, want, tol float64) bool { return x > want-tol && x < want+tol }
Output: period 8760 hours periods 10000 exact mean 76134 simulated mean within 5% of exact: true