engine: realistic config bounds, enforced and served
ConfigBounds (students 10-500, edgesPerNode 1-8, forwardProb 0-0.9,
triangleProb 0-1) caps what RunScenario accepts: a student does not
keep 150 close friendships and a guaranteed forward is not a real
base rate. numEducated gains its missing upper limit (numStudents).
Bounds-side validation also protects the public server from absurd
numStudents values. GET /api/config/default now returns
{config, bounds} so the frontend can drive its controls from the
same numbers; the frontend does not call it yet, so this commit
changes no UI behaviour.
This commit is contained in:
parent
232faf892e
commit
bd890384e5
7 changed files with 194 additions and 15 deletions
|
|
@ -1,5 +1,5 @@
|
|||
// Code generated by tygo. DO NOT EDIT.
|
||||
import type { Config, Result, Strategy } from "./engine";
|
||||
import type { Bounds, Config, Result, Strategy } from "./engine";
|
||||
|
||||
//////////
|
||||
// source: api.go
|
||||
|
|
@ -9,6 +9,15 @@ thin on purpose: decode, run the engine, encode. All validation lives in
|
|||
the engine; the API only translates errors into status codes.
|
||||
*/
|
||||
|
||||
/**
|
||||
* DefaultConfigResponse is the body of GET /api/config/default: the
|
||||
* default world plus the engine's field bounds, so the frontend drives
|
||||
* its controls and clamping from the same numbers the engine enforces.
|
||||
*/
|
||||
export interface DefaultConfigResponse {
|
||||
config: Config;
|
||||
bounds: Bounds;
|
||||
}
|
||||
/**
|
||||
* ComparisonResponse bundles what the dashboard needs to render one
|
||||
* comparison: the config that was run, echoed back so frontend state stays
|
||||
|
|
|
|||
|
|
@ -27,6 +27,33 @@ export interface Config {
|
|||
thresholdSeed: number /* uint64 */;
|
||||
educationSeed: number /* uint64 */; // used by the random strategy only
|
||||
}
|
||||
/**
|
||||
* IntBounds is an inclusive allowed range for an integer Config field.
|
||||
*/
|
||||
export interface IntBounds {
|
||||
min: number /* int */;
|
||||
max: number /* int */;
|
||||
}
|
||||
/**
|
||||
* FloatBounds is an inclusive allowed range for a float Config field.
|
||||
*/
|
||||
export interface FloatBounds {
|
||||
min: number /* float64 */;
|
||||
max: number /* float64 */;
|
||||
}
|
||||
/**
|
||||
* Bounds gives the allowed range for every absolute Config field. These
|
||||
* are realism limits, not mathematical ones: a student does not keep 150
|
||||
* close friendships, and a guaranteed forward is not a plausible base
|
||||
* rate. numEducated and origin are relational (0..numStudents and
|
||||
* 0..numStudents-1) and therefore not listed; seeds are unrestricted.
|
||||
*/
|
||||
export interface Bounds {
|
||||
numStudents: IntBounds;
|
||||
edgesPerNode: IntBounds;
|
||||
triangleProb: FloatBounds;
|
||||
forwardProb: FloatBounds;
|
||||
}
|
||||
/**
|
||||
* Result is the outcome of one scenario run.
|
||||
*/
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue