Skip to content

feat: add projection grammar#206

Merged
pesap merged 9 commits intomainfrom
feat/projection-reduce-tdd-slice
Apr 29, 2026
Merged

feat: add projection grammar#206
pesap merged 9 commits intomainfrom
feat/projection-reduce-tdd-slice

Conversation

@pesap
Copy link
Copy Markdown
Collaborator

@pesap pesap commented Apr 28, 2026

Summary

This PR adds and hardens projection-based reduce support for nodal allocation, and aligns compiler behavior, tests, and docs.

What is new

  • Added top-level projection parsing/AST support and semantic validation.
  • Added reduce-projection expression lowering (e.g. reduce "ai" { sum "investment" }).
  • Extended tuple-domain reduction handling so projected reductions bind correctly to tuple rows.
  • Updated nodal-allocation example and related CLI/KDL test expectations.
  • Tightened parser behavior for reduce-projection detection (anchored parse).
  • Updated docs/arco-spec.md and examples/README.md to match implemented behavior.

New KDL example (expression used in a constraint)

data "links" source="data/links.csv" {
  set "area" as="a"
  set "tech" as="i"
  alias "generators" column="gen"
  alias "buses" column="bus"

  set "generators" as="g"
  set "buses" as="b"

  set "feasible_links" {
    index "a" { in "area" }
    index "i" { in "tech" }
    index "g" { in "generators" }
    index "b" { in "buses" }
    filter { feasible > 0 }
  }

  param "mw_target" {
    index "a"
    index "i"
    reduce "max"
  }
}

set "feasible_ai" {
  in "feasible_links"
  index "a" { in "area" }
  index "i" { in "tech" }
}

projection "ai" {
  from "feasible_links"
  to "a" "i"
}

model "NodalAllocation" {
  param "mw_target" {
    index "a"
    index "i"
  }

  control "investment" lower=0 {
    index "a" { in "feasible_links" }
    index "i" { in "feasible_links" }
    index "g" { in "feasible_links" }
    index "b" { in "feasible_links" }
  }

  expression "investment_by_area_tech" {
    reduce "ai" {
      sum "investment"
    }
  }

  constraint "enforce_mw_target" {
    index "a" { in "feasible_ai" }
    index "i" { in "feasible_ai" }
    expression {
      investment_by_area_tech[a,i] >= mw_target[a,i]
    }
  }

  minimize "obj" { 0 }
}

scenario "S1" {
  use "NodalAllocation"
}

Test strategy

  • just ci

pesap added 3 commits April 28, 2026 14:16
Expand reduction binding domains from tuple rows when set values are empty and filter candidates by already-bound tuple components.\n\nThis fixes nodal-allocation print-model failures where reduce projections produced empty tuple subsets at compile time. Also aligns tuple-related CLI/compile tests with current investment naming and emitted constraint counts.
Replace panic-prone expects in tuple subset handling with explicit semantic errors, tighten an internal slice parameter, and remove clippy single-char-pattern warning in semantic validation tests.
@github-actions github-actions Bot added the docs label Apr 29, 2026
@pesap pesap merged commit 0e30225 into main Apr 29, 2026
29 of 34 checks passed
@pesap pesap deleted the feat/projection-reduce-tdd-slice branch April 29, 2026 05:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant