1 个不稳定版本
0.1.0 | 2023 年 9 月 14 日 |
---|
#1360 在 算法
380KB
6K SLoC
xcsp3-rust
描述
这个库是用 Rust 实现的,并使用 MIT 许可协议。
这个库的目的是将 XCSP 文件读入 Rust 约束编程求解器。
您可以通过这个网站了解 XCSP3 的语义 http://xcsp.org/。
我会继续改进这个代码,以支持更多的约束并修复可能的错误。
如果您有任何想告诉我的,请随时联系我。
用法
只需将以下依赖项添加到您的项目的 Cargo.toml 文件中
[dependencies]
xcsp3-rust = "0.1.0"
库会自动构建并静态链接到您的二进制文件。
示例
fn main()
{
let xml_file = ".//instances//my-example.xml";
let model = XcspXmlModel::from_path(xml_file).unwrap();
let variable = model.build_variables();
println!("variables:");
for v in variable.iter() {
println!("\t{}", v);
match v {
XVariableType::XVariableNone(_) => {}
XVariableType::XVariableArray(_) => {}
XVariableType::XVariableInt(_) => {}
XVariableType::XVariableTree(_) => {}
}
}
println!("constraints:");
for c in model.build_constraints(&variable).iter_mut() {
println!("\t{}", c);
match c {
XConstraintType::XConstraintNone(_) => {}
XConstraintType::XExtension(_) => {}
XConstraintType::XAllDifferent(_) => {}
XConstraintType::XAllDifferentExcept(_) => {}
XConstraintType::XInstantiation(_) => {}
XConstraintType::XAllEqual(_) => {}
XConstraintType::XOrdered(_) => {}
XConstraintType::XRegular(_) => {}
XConstraintType::XMdd(_) => {}
XConstraintType::XIntention(_) => {}
XConstraintType::XGroup(_) => {}
XConstraintType::XSum(_) => {}
XConstraintType::XMaximum(_) => {}
XConstraintType::XMinimum(_) => {}
XConstraintType::XElement(_) => {}
XConstraintType::XSlide(_) => {}
XConstraintType::XCount(_) => {}
XConstraintType::XNValues(_) => {}
XConstraintType::XCardinality(_) => {}
XConstraintType::XChannel(_) => {}
XConstraintType::XCumulative(_) => {}
XConstraintType::XNoOverlap(_) => {}
XConstraintType::XStretch(_) => {}
}
}
println!("objectives:");
for o in model.build_objectives(&variable).iter() {
println!("\t{}", o);
match o {
XObjectivesType::XObjectiveNone(_) => {}
XObjectivesType::Minimize(e) => match e {
XObjective::XObjectiveElement(_) => {}
XObjective::XObjectiveExpression(_) => {}
},
XObjectivesType::Maximize(e) => match e {
XObjective::XObjectiveElement(_) => {}
XObjective::XObjectiveExpression(_) => {}
},
}
}
}
架构图
主要架构
graph BT
A["XCSP(xml file)"] --serde--> B(XcspXmlModel)
B --parser--> C([XVariableSet])
B --parser--> D([XConstraintSet])
B --parser--> E([XObjectivesSet])
C --reader--> F[/example.rs/]
D --reader--> F
E --reader--> F
XVariableSet
graph LR
C([XVariableSet]) -.->XVariableType(XVariableType)
XVariableType --> XVariableArray(XVariableArray)
XVariableType --> XVariableInt(XVariableInt)
XVariableType --> XVariableTree(XVariableTree)
XVariableTree -.domain.-> XDomainInteger(XDomainInteger)
XVariableInt -.domain.-> XDomainInteger
XVariableArray -.domain.-> XDomainInteger
XDomainInteger -.-> XIntegerType(XIntegerType)
XIntegerType -->IntegerValue(IntegerValue)
XIntegerType -->IntegerInterval(IntegerInterval)
XIntegerType -->XIntegerSymbolic(XIntegerSymbolic)
XConstraintSet
graph LR
D([XConstraintSet]) -.-> XConstraintType(XConstraintType)
XConstraintType --> XExtension(XExtension) -.scope.-> Scope(XVarVal)
XConstraintType --> XAllDifferent(XAllDifferent)-.scope.-> Scope
XConstraintType --> XAllDifferentExcept(XAllDifferentExcept)-.scope.-> Scope
XConstraintType --> XInstantiation(XInstantiation)-.scope.-> Scope
XConstraintType --> XAllEqual(XAllEqual)-.scope.-> Scope
XConstraintType --> XOrdered(XOrdered)-.scope.-> Scope
XConstraintType --> XRegular(XRegular)-.scope.-> Scope
XConstraintType -->XMdd(XMdd)-.scope.-> Scope
XConstraintType -->XIntention(XIntention)-.scope.-> Scope
XConstraintType -->XGroup(XGroup)-.scope.-> Scope
XConstraintType -->XSum(XSum)-.scope.-> Scope
XConstraintType -->XMaximum(XMaxMin)-.scope.-> Scope
XConstraintType -->XMinimum(XMaxMin)-.scope.-> Scope
XConstraintType -->XElement(XElement)-.scope.-> Scope
XConstraintType -->XSlide(XSlide)-.scope.-> Scope
XConstraintType -->XCount(XCount)-.scope.-> Scope
XConstraintType -->XNValues(XNValues)-.scope.-> Scope
XConstraintType -->XCardinality(XCardinality)-.scope.-> Scope
XConstraintType -->XChannel(XChannel)-.scope.-> Scope
XConstraintType -->XCumulative(XCumulative)-.scope.-> Scope
XConstraintType -->XNoOverlap(XNoOverlap)-.scope.-> Scope
XConstraintType -->XNoOverlapKDim(XNoOverlap)-.scope.-> Scope
XConstraintType --> XStretch(XStretch)-.scope.-> Scope
Scope -->IntVar(IntVar is a variable)
Scope -->IntVal(IntVal is a value)
XObjectivesSet
graph LR
E([XObjectivesSet]) -.-> T(XObjectivesType)
%% XVariableArray(XVariableArray)
T --> Minimize(Minimize)
T --> Maximize(Maximize)
Minimize --> XObjective(XObjective)
Maximize --> XObjective(XObjective)
XObjective --> XObjectiveElement(XObjectiveElement)
XObjective --> XObjectiveExpression(XObjectiveExpression)
许可证
MIT 许可协议
作者
luhan zhen
提示:我的代码可能不是最好的,但我将不断改进它,以更好地构建我们的 'CP' 社区。
依赖项
~4–13MB
~139K SLoC