-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
changes to the JSON solution format + extra docs
- Loading branch information
Showing
4 changed files
with
69 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,66 +1,88 @@ | ||
use serde::{Deserialize, Serialize}; | ||
|
||
/// The JSON representation of a problem instance | ||
#[derive(Serialize, Deserialize, Clone)] | ||
pub struct JsonInstance { | ||
#[serde(rename = "Name")] | ||
/// The name of the instance | ||
pub name: String, | ||
/// Set of items to be produced | ||
#[serde(rename = "Items")] | ||
pub items: Vec<JsonItem>, | ||
/// Set of bins where the items are to be placed (for Bin Packing problems) | ||
#[serde(rename = "Objects")] | ||
#[serde(skip_serializing_if = "Option::is_none")] | ||
pub bins: Option<Vec<JsonBin>>, | ||
/// A strip where the items are to be placed (for Strip Packing problems) | ||
#[serde(rename = "Strip")] | ||
#[serde(skip_serializing_if = "Option::is_none")] | ||
pub strip: Option<JsonStrip>, | ||
} | ||
|
||
/// The JSON representation of a bin | ||
#[derive(Serialize, Deserialize, Clone)] | ||
#[serde(rename_all = "PascalCase")] | ||
pub struct JsonBin { | ||
/// The cost of using this bin | ||
pub cost: u64, | ||
/// Number of this bin available | ||
pub stock: u64, | ||
/// Polygon shape of the bin | ||
pub shape: JsonPoly, | ||
/// A list of zones with different quality levels | ||
#[serde(skip_serializing_if = "Vec::is_empty", default)] | ||
pub zones: Vec<JsonQualityZone>, | ||
} | ||
|
||
/// The JSON representation of a strip | ||
#[derive(Serialize, Deserialize, Clone)] | ||
#[serde(rename_all = "PascalCase")] | ||
pub struct JsonStrip { | ||
pub height: f64, | ||
} | ||
|
||
/// The JSON representation of an item | ||
#[derive(Serialize, Deserialize, Clone)] | ||
#[serde(rename_all = "PascalCase")] | ||
pub struct JsonItem { | ||
/// Number of times this item should be produced | ||
pub demand: u64, | ||
/// List of allowed orientations angles (in degrees). | ||
/// If Some(), only the specified angles are allowed | ||
/// If None, continuous rotation is allowed | ||
/// Some(_) if only the specified angles are allowed; None if continuous rotation is allowed | ||
#[serde(skip_serializing_if = "Option::is_none")] | ||
pub allowed_orientations: Option<Vec<f64>>, | ||
/// Polygon shape of the item | ||
pub shape: JsonPoly, | ||
/// A list of zones with different quality requirements | ||
#[serde(skip_serializing_if = "Vec::is_empty", default)] | ||
pub zones: Vec<JsonQualityZone>, | ||
/// The value of the item (for knapsack problems) | ||
pub value: Option<u64>, | ||
/// The quality required for the entire item | ||
pub base_quality: Option<usize>, | ||
} | ||
|
||
/// A polygon represented as an outer boundary and a list of holes | ||
#[derive(Serialize, Deserialize, Clone)] | ||
#[serde(rename_all = "PascalCase")] | ||
pub struct JsonPoly { | ||
/// The outer boundary of the polygon | ||
pub outer: JsonSimplePoly, | ||
/// A list of holes in the polygon (if any) | ||
#[serde(skip_serializing_if = "Vec::is_empty", default)] | ||
pub inner: Vec<JsonSimplePoly>, | ||
} | ||
|
||
/// A simple polygon represented as a list of points (x, y) | ||
#[derive(Serialize, Deserialize, Clone)] | ||
pub struct JsonSimplePoly(pub Vec<(f64, f64)>); | ||
|
||
/// A zone with a specific quality level | ||
#[derive(Serialize, Deserialize, Clone)] | ||
#[serde(rename_all = "PascalCase")] | ||
pub struct JsonQualityZone { | ||
/// The quality level of this zone | ||
pub quality: usize, | ||
/// The polygon shape of this zone | ||
pub shape: JsonPoly, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,49 +1,73 @@ | ||
use serde::{Deserialize, Serialize}; | ||
|
||
/// Representation of a solution | ||
#[derive(Serialize, Deserialize, Clone)] | ||
#[serde(rename_all = "PascalCase")] | ||
pub struct JsonSolution { | ||
/// Sum of the area of the produced items divided by the sum of the area of the containers | ||
pub usage: f64, | ||
/// The time it took to generate the solution in seconds | ||
pub run_time_sec: u64, | ||
/// Layouts which compose the solution | ||
pub layouts: Vec<JsonLayout>, | ||
} | ||
|
||
/// Representation how a set of items are placed in a certain container | ||
#[derive(Serialize, Deserialize, Clone)] | ||
#[serde(rename_all = "PascalCase")] | ||
pub struct JsonLayout { | ||
pub object_type: JsonObjectType, | ||
/// The container that was used | ||
pub container: JsonContainer, | ||
/// The items placed in the container and where they were placed | ||
pub placed_items: Vec<JsonPlacedItem>, | ||
/// Some statistics about the layout | ||
pub statistics: JsonLayoutStats, | ||
} | ||
|
||
/// Represents an item placed in a container | ||
#[derive(Serialize, Deserialize, Clone)] | ||
#[serde(rename_all = "PascalCase")] | ||
pub struct JsonPlacedItem { | ||
pub item_index: usize, | ||
/// The index of the item in the instance | ||
pub index: usize, | ||
/// The transformation applied to the item to place it in the container | ||
pub transformation: JsonTransformation, | ||
} | ||
|
||
/// Represents a proper rigid transformation defined as a rotation followed by translation | ||
#[derive(Serialize, Deserialize, Clone)] | ||
#[serde(rename_all = "PascalCase")] | ||
pub struct JsonTransformation { | ||
/// The rotation angle in radians | ||
pub rotation: f64, | ||
/// The translation vector (x, y) | ||
pub translation: (f64, f64), | ||
} | ||
|
||
/// Some statistics about the layout | ||
#[derive(Serialize, Deserialize, Clone)] | ||
#[serde(rename_all = "PascalCase")] | ||
pub struct JsonLayoutStats { | ||
// | ||
pub usage: f64, | ||
/// The percentage of the container that is packed with items | ||
pub usage: f64 | ||
} | ||
|
||
/// Type of container that was used | ||
#[derive(Serialize, Deserialize, Clone)] | ||
#[serde(rename_all = "PascalCase")] | ||
pub enum JsonObjectType { | ||
Object { id: usize }, | ||
#[serde(tag = "Type", content = "Params")] | ||
pub enum JsonContainer { | ||
Bin { | ||
/// The index of the object in the instance | ||
#[serde(rename = "Index")] | ||
index: usize | ||
}, | ||
Strip { | ||
/// The length of the strip (variable) | ||
#[serde(rename = "Length")] | ||
width: f64, | ||
/// The height of the strip (fixed) | ||
#[serde(rename = "Height")] | ||
height: f64, | ||
}, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters