2 releases

0.1.1 Aug 12, 2024
0.1.0 Jun 21, 2024

#521 in Encoding

Download history 180/week @ 2024-06-21 5/week @ 2024-06-28 8/week @ 2024-07-05 2/week @ 2024-07-26 113/week @ 2024-08-09 17/week @ 2024-08-16

130 downloads per month

MPL-2.0 license

140KB
3K SLoC

XCSP3 Serde

xcsp3-serde is a Rust library that provides serialization and deserialization support for the XCSP3 (XML) format using the serde library. XCSP3 is a representation used to represent decision and optimization problems. This format can be used by some solvers of these types of problems, or used to further process the problem.

Getting Started

Install the library using cargo:

cargo install xcsp3-serde

Read the documentation for more information about how to use the library.

Limitations

This library currently only supports a subset of the XCSP3 format. All features of the XCSP3-core format are supported, but many features outside the core format are not yet supported. It is the aim of this library to support the full XCSP3 format in the future.

License

This project is licensed under the MPL-2.0 License. See the LICENSE file for details.


lib.rs:

Serialization of the XCSP3 (core) format

XCSP3 is an integrated format for representing combinatorial constrained problems, which can deal with mono/multi optimization, many types of variables, cost functions, reification, views, annotations, variable quantification, distributed, probabilistic and qualitative reasoning. It is also compact, and easy to read and to parse. The objective of XCSP3 is to ease the effort required to test and compare different algorithms by providing a common test-bed of combinatorial constrained instances.

This crate focuses on the (de-)serializeation of the XCSP3 format. It can be used to parse an XCSP3 XML file into the provided rust types, or writing the provided rust types to an XCSP3 XML file.

Getting Started

Install xcsp3-serde and quick-xml for your package:

cargo add xcsp3-serde quick-xml

Once these dependencies have been installed to your crate, you could deserialize a XCSP3 XML file as follows:

// let path = Path::new("/lorem/ipsum/instance.xml");
let rdr = BufReader::new(File::open(path).unwrap());
let instance: Instance = quick_xml::de::from_reader(rdr).unwrap();
// ... process XCSP3 ...

If, however, you want to serialize a XCSP3 instance you could follow the following fragment:

let instance = Instance::<String>::default();
// ... create XCSP3 instance ...
let xml_str = quick_xml::se::to_string(&instance).unwrap();

Note that quick_xml::se::to_writer, using a buffered file writer, would be preferred when writing larger instances.

Limitations

Not all XCSP3 features are currently implemented, the functionality of XCSP3-core is generally implemented and supported. This allows users to work with the most common constraint types and representations. Future updates will focus on expanding the range of supported XCSP3 features.

Dependencies

~1.6–2.5MB
~51K SLoC