let domains author their own pass-2 estimator as formulas, not Python
Pass 2 previously only knew one estimator: a hardcoded physics model that matches dimensions literally named platform/actuator/energy_storage. Any domain outside that shape (e.g. archery) got all-zero estimates and failed every combo. Domains can now declare free variables and per-metric formulas as data instead; a safe AST-based evaluator (engine/formula.py, no eval()) resolves declared entity properties via dep(key, constraint_type) and generalizes the existing hand-nested mass-budget search into an N-variable recursive optimizer. Fully additive -- the legacy platform/actuator/ energy_storage path is untouched and still runs unchanged for every domain that declares no formulas. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
56
src/physcom_web/templates/domains/_formulas_table.html
Normal file
56
src/physcom_web/templates/domains/_formulas_table.html
Normal file
@@ -0,0 +1,56 @@
|
||||
<table id="formulas-table">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Metric</th>
|
||||
<th>Formula</th>
|
||||
<th></th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{% for mf in domain.metric_formulas %}
|
||||
<tr>
|
||||
<td>{{ mf.metric_name }}</td>
|
||||
<td><code>{{ mf.formula }}</code></td>
|
||||
<td class="actions">
|
||||
<button class="btn btn-sm"
|
||||
onclick="this.closest('tr').nextElementSibling.style.display='table-row'; this.closest('tr').style.display='none'">
|
||||
Edit
|
||||
</button>
|
||||
<form method="post"
|
||||
hx-post="{{ url_for('domains.formula_delete', domain_id=domain.id, formula_id=mf.id) }}"
|
||||
hx-target="#formulas-section" hx-swap="innerHTML"
|
||||
class="inline-form">
|
||||
<button type="submit" class="btn btn-sm btn-danger">Del</button>
|
||||
</form>
|
||||
</td>
|
||||
</tr>
|
||||
<tr class="edit-row" style="display:none">
|
||||
<form method="post"
|
||||
hx-post="{{ url_for('domains.formula_edit', domain_id=domain.id, formula_id=mf.id) }}"
|
||||
hx-target="#formulas-section" hx-swap="innerHTML">
|
||||
<td><input name="metric_name" value="{{ mf.metric_name }}" required></td>
|
||||
<td><input name="formula" value="{{ mf.formula }}" required></td>
|
||||
<td>
|
||||
<button type="submit" class="btn btn-sm btn-primary">Save</button>
|
||||
<button type="button" class="btn btn-sm"
|
||||
onclick="this.closest('tr').style.display='none'; this.closest('tr').previousElementSibling.style.display=''">
|
||||
Cancel
|
||||
</button>
|
||||
</td>
|
||||
</form>
|
||||
</tr>
|
||||
{% endfor %}
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
<h3>Add Formula</h3>
|
||||
<form method="post"
|
||||
hx-post="{{ url_for('domains.formula_add', domain_id=domain.id) }}"
|
||||
hx-target="#formulas-section" hx-swap="innerHTML"
|
||||
class="dep-add-form">
|
||||
<div class="form-row">
|
||||
<input name="metric_name" placeholder="metric name" required>
|
||||
<input name="formula" placeholder='formula, e.g. draw_weight_chosen * 2' required>
|
||||
<button type="submit" class="btn btn-primary">Add</button>
|
||||
</div>
|
||||
</form>
|
||||
64
src/physcom_web/templates/domains/_free_vars_table.html
Normal file
64
src/physcom_web/templates/domains/_free_vars_table.html
Normal file
@@ -0,0 +1,64 @@
|
||||
<table id="free-vars-table">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Name</th>
|
||||
<th>Order</th>
|
||||
<th>Floor formula</th>
|
||||
<th>Ceiling formula</th>
|
||||
<th></th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{% for fv in domain.free_variables %}
|
||||
<tr>
|
||||
<td>{{ fv.name }}</td>
|
||||
<td>{{ fv.sort_order }}</td>
|
||||
<td><code>{{ fv.floor_formula }}</code></td>
|
||||
<td><code>{{ fv.ceiling_formula }}</code></td>
|
||||
<td class="actions">
|
||||
<button class="btn btn-sm"
|
||||
onclick="this.closest('tr').nextElementSibling.style.display='table-row'; this.closest('tr').style.display='none'">
|
||||
Edit
|
||||
</button>
|
||||
<form method="post"
|
||||
hx-post="{{ url_for('domains.free_var_delete', domain_id=domain.id, fv_id=fv.id) }}"
|
||||
hx-target="#free-vars-section" hx-swap="innerHTML"
|
||||
class="inline-form">
|
||||
<button type="submit" class="btn btn-sm btn-danger">Del</button>
|
||||
</form>
|
||||
</td>
|
||||
</tr>
|
||||
<tr class="edit-row" style="display:none">
|
||||
<form method="post"
|
||||
hx-post="{{ url_for('domains.free_var_edit', domain_id=domain.id, fv_id=fv.id) }}"
|
||||
hx-target="#free-vars-section" hx-swap="innerHTML">
|
||||
<td><input name="name" value="{{ fv.name }}" required></td>
|
||||
<td><input name="sort_order" type="number" step="1" value="{{ fv.sort_order }}"></td>
|
||||
<td><input name="floor_formula" value="{{ fv.floor_formula }}" required></td>
|
||||
<td><input name="ceiling_formula" value="{{ fv.ceiling_formula }}" required></td>
|
||||
<td>
|
||||
<button type="submit" class="btn btn-sm btn-primary">Save</button>
|
||||
<button type="button" class="btn btn-sm"
|
||||
onclick="this.closest('tr').style.display='none'; this.closest('tr').previousElementSibling.style.display=''">
|
||||
Cancel
|
||||
</button>
|
||||
</td>
|
||||
</form>
|
||||
</tr>
|
||||
{% endfor %}
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
<h3>Add Free Variable</h3>
|
||||
<form method="post"
|
||||
hx-post="{{ url_for('domains.free_var_add', domain_id=domain.id) }}"
|
||||
hx-target="#free-vars-section" hx-swap="innerHTML"
|
||||
class="dep-add-form">
|
||||
<div class="form-row">
|
||||
<input name="name" placeholder="name, e.g. draw_weight_chosen" required>
|
||||
<input name="sort_order" type="number" step="1" placeholder="order" value="0">
|
||||
<input name="floor_formula" placeholder='floor formula, e.g. dep("draw_weight", "range_min")' required>
|
||||
<input name="ceiling_formula" placeholder='ceiling formula, e.g. dep("draw_weight", "range_max")' required>
|
||||
<button type="submit" class="btn btn-primary">Add</button>
|
||||
</div>
|
||||
</form>
|
||||
@@ -33,4 +33,18 @@
|
||||
<div id="metrics-section">
|
||||
{% include "domains/_metrics_table.html" %}
|
||||
</div>
|
||||
|
||||
<h2>Free Variables</h2>
|
||||
<p class="hint">Quantities pass 2's estimator searches to maximize this domain's composite score. Leave empty for domains where nothing needs sizing.</p>
|
||||
|
||||
<div id="free-vars-section">
|
||||
{% include "domains/_free_vars_table.html" %}
|
||||
</div>
|
||||
|
||||
<h2>Metric Formulas</h2>
|
||||
<p class="hint">How each metric's raw value is computed from declared entity properties (via <code>dep(key, constraint_type="provides")</code>) and any free variable above. If this domain declares any formulas, pass 2 uses them instead of the built-in vehicle physics model.</p>
|
||||
|
||||
<div id="formulas-section">
|
||||
{% include "domains/_formulas_table.html" %}
|
||||
</div>
|
||||
{% endblock %}
|
||||
|
||||
Reference in New Issue
Block a user