Petri.Config (petri v0.1.0)

Copy Markdown View Source

Typed config validation for Petri.run/2.

Uses Zoi to validate the config map against a typed schema. Invalid configs return {:error, reasons}.

Encoding-specific schemas

The schema is a discriminated union on :encoding. Fields shared across all encodings live in a common base; encoding-specific fields (:bounds, :crossover, :mutation, etc.) are added per variant.

Example

iex> {:ok, config} = Petri.Config.parse(%{
...>   encoding: :binary, length: 8,
...>   population_size: 20, max_generations: 10
...> })
iex> config.encoding
:binary

iex> {:error, err} = Petri.Config.parse(%{
...>   encoding: :binary, length: 8,
...>   population_size: 0, max_generations: 10
...> })
iex> is_list(err)
true

Summary

Functions

Parses and validates a map against the config schema.

Functions

parse(config)

Parses and validates a map against the config schema.

Returns {:ok, typed_map} on success or {:error, err} on failure.