有限拟阵建模、共同独立集选择与可检查的最优性证书
| 使用者 | 输入与处理 | 输出和可运行例子 |
|---|---|---|
| 排班、申请分配工具开发者 | 申请 ID、部门上限与时段上限;构造两个分区拟阵并求交 | 最大数量的可行申请、可独立检查的秩上界;examples/quotas |
| 网络设计与图算法开发者 | 端点和边类别;图拟阵与分区拟阵求交,再按两个森林分层 | 不成环且满足配额的边集、独立森林分解;examples/network |
| 二进制编码与特征分析开发者 | GF(2) 列向量、整数收益和待收缩特征 | 最优加权基、收缩后的精确模型、可恢复的秩快照;examples/features |
moon new selection-demo --user demo --name selection-demo
cd selection-demo
moon add yujieMamba/moonmatroid@0.1.0import {
"yujieMamba/moonmatroid" @matroid,
"moonbitlang/core/debug",
}
pkgtype(kind: "executable")///|
fn main {
let department = @matroid.Matroid::partition([0, 0, 1], [1, 1]) catch { _ => abort("department") }
let slot = @matroid.Matroid::partition([0, 1, 0], [1, 1]) catch { _ => abort("slot") }
let result = @matroid.intersect(department, slot) catch { _ => abort("intersection") }
@matroid.verify_intersection(department, slot, result) catch { _ => abort("certificate") }
println("quota selection: \{@debug.to_string(result.elements)}")
println("upper bound: \{result.left_rank + result.right_rank}")
}moon check --target js --deny-warn
moon run cmd/main --target js --deny-warnquota selection: [1, 2]
upper bound: 2| 能力 | 入口 | 关键语义 |
|---|---|---|
| 基础模型 | Matroid::uniform/free/zero | 固定秩上限、自由拟阵、全环拟阵 |
| 分区与层次配额 | Matroid::partition/laminar | 分组上限;层次集合必须嵌套或不相交 |
| 图与 GF(2) | Matroid::graphic/binary | 支持自环、平行边、不连通图;位向量精确消元 |
| 二部可匹配性 | Matroid::transversal、transversal_assignment | 选中的左端点是否能匹配;恢复最大匹配见证 |
| 外部有限模型 | Matroid::from_ranks | 至多 12 元;逐项检查所有局部秩公理,不信任外部函数 |
| 结构查询 | rank/independent/nullity/closure/basis/is_basis/is_circuit/spans/is_flat | 精确秩与闭包、基、回路 |
| 交换结构 | fundamental_circuit/fundamental_cocircuit/loops/coloops/connectivity | 明确前置条件;不合法请求抛错 |
| 变换 | relabel/restrict_to/delete/contract/dual/truncate/direct_sum | 依赖集也可收缩,使用标准秩公式 |
| 扩张与分解 | add_loop/add_coloop/parallel_extension/free_extension/series_extension | 新元素 ID 为旧 ground 大小 |
| 平行类和连通分量 | parallel_classes/simplify/components/component_factors/is_simple/is_connected | 简化保留原 ID 映射;环、余环各为单元素分量 |
| 加权优化 | weighted_basis、max_weight_independent | 整数权;基可含负权,后者忽略非正权;总权重 Int64 |
| 无权求交 | intersect、verify_intersection | 最大基数共同独立集;独立复算秩上界 |
| 并集分解 | union_partition、verify_partition | 复制 ground 上求交;输出互不重叠的各拟阵独立块 |
| 有界枚举与不变量 | bases/circuits/flats/rank_distribution/tutte/tutte_at | 完整枚举或报错,不返回伪装成完整的部分结果 |
| 交换格式 | encode、decode_snapshot | 版本化 ASCII 秩表,恢复时重新检查公理 |
|I| = rank_M1(U) + rank_M2(E \ U)git clone https://github.com/yujieMamba/moonmatroid.git
cd moonmatroid
moon info
moon fmt --check
moon check --target js --deny-warn
moon build --target js --deny-warn
moon test --target js --deny-warn
moon run examples/quotas --target js --deny-warn
moon run examples/network --target js --deny-warn
moon run examples/features --target js --deny-warnpython tools/oracle.py
moon fmt
git diff --exit-codepub suberror MatroidError {
InvalidInput(String)
InvalidCertificate(String)
BudgetExceeded(String)
}fn Matroid::fundamental_circuit(self : Matroid, independent : Array[Int], e : Int) -> Array[Int] raise MatroidErrorfn Matroid::fundamental_cocircuit(self : Matroid, basis : Array[Int], e : Int) -> Array[Int] raise MatroidErrorfn Matroid::max_weight_independent(self : Matroid, weights : Array[Int]) -> Selection raise MatroidErrorfn Matroid::rank_distribution(self : Matroid, max_subsets? : Int) -> Array[Array[Int64]] raise MatroidErrorfn Matroid::tutte_at(self : Matroid, x : Int, y : Int, max_subsets? : Int) -> Int64 raise MatroidErrorfn Matroid::weighted_basis(self : Matroid, weights : Array[Int], maximize? : Bool) -> Selection raise MatroidErrorpub(all) struct TutteTerm {
x_degree : Int
y_degree : Int
coefficient : Int64
}pub(all) struct UnionSelection {
elements : Array[Int]
groups : Array[Array[Int]]
proof : Intersection
}fn transversal_assignment(rights : Int, neighbors : Array[Array[Int]], subset : Array[Int]) -> Array[(Int, Int)] raise MatroidErrorfn verify_intersection(left : Matroid, right : Matroid, result : Intersection) -> Unit raise MatroidError