ttpgen/data_set.rs
1use serde::{Serialize, Deserialize};
2
3/// All raw data parsed from a TTP XML instance.
4///
5/// Contains all information necessary to generate solutions,
6/// including teams, slots, distances, and constraints.
7#[derive(Clone, Debug, Serialize, Deserialize)]
8pub struct Rawdata {
9 /// Name of the instance.
10 pub instance_name: String,
11 /// List of teams participating in the tournament.
12 pub teams: Vec<Team>,
13 /// List of time slots or rounds.
14 pub slots: Vec<Slot>,
15 /// Pair travel distances between teams.
16 pub distances: Vec<Distance>,
17 /// Capacity constraints for the tournament.
18 pub capacity_constraints: Vec<CapacityConstraints>,
19 /// Separation constraints for the tournament.
20 pub separation_constraints: Vec<SeparationConstraints>,
21}
22
23/// Represents the travel distance between two teams.
24#[derive(Clone, Debug, Serialize, Deserialize, PartialEq, Eq, Hash)]
25pub struct Distance {
26 /// Distance value between two teams.
27 pub dist: i32,
28 /// First team ID.
29 pub team1: i32,
30 /// Second team ID.
31 pub team2: i32,
32}
33
34impl Distance {
35 /// Creates a new Distance with default values (0).
36 pub fn new() -> Self {
37 Self {
38 dist: 0,
39 team1: 0,
40 team2: 0,
41 }
42 }
43}
44
45/// Represents a team in the tournament.
46#[derive(Clone, Debug, Serialize, Deserialize, PartialEq, Eq, Hash)]
47pub struct Team {
48 /// Unique team ID.
49 pub id: i32,
50 /// League or division ID.
51 pub league: i32,
52 /// Name of the team.
53 pub name: String,
54 /// Team group or category.
55 pub team_groups: i32,
56}
57
58impl Team {
59 /// Creates a new Team with default values.
60 pub fn new() -> Self {
61 Self {
62 id: 0,
63 league: 0,
64 name: "Null".to_string(),
65 team_groups: 0,
66 }
67 }
68}
69
70/// Represents a time slot or round in the tournament.
71#[derive(Clone, Debug, Serialize, Deserialize, PartialEq, Eq, Hash)]
72pub struct Slot {
73 /// Slot ID.
74 pub id: i32,
75 /// Name or label of the slot.
76 pub name: String,
77}
78
79impl Slot {
80 /// Creates a new Slot with default values.
81 pub fn new() -> Self {
82 Self {
83 id: 0,
84 name: "Null".to_string(),
85 }
86 }
87}
88
89/// Represents capacity constraints for the tournament.
90#[derive(Clone, Debug, Serialize, Deserialize)]
91pub struct CapacityConstraints {
92 /// Interval parameter
93 pub c_intp: i32,
94 /// Maximum allowed occurrences.
95 pub c_max: i32,
96 /// Minimum required occurrences.
97 pub c_min: i32,
98 /// Mode type 1 ('A', 'H').
99 pub c_mode1: char,
100 /// Mode type 2 (string).
101 pub c_mode2: String,
102 /// Penalty value for violation.
103 pub c_penalty: i32,
104 /// First affected team group.
105 pub c_team_groups1: i32,
106 /// Second affected team group.
107 pub c_team_groups2: i32,
108 /// Type of constraint (description).
109 pub c_type: String,
110}
111
112impl CapacityConstraints {
113 /// Creates a new CapacityConstraints instance with default values.
114 pub fn new() -> Self {
115 Self {
116 c_intp: 0,
117 c_max: 0,
118 c_min: 0,
119 c_mode1: 'N',
120 c_mode2: "Null".to_string(),
121 c_penalty: 0,
122 c_team_groups1: 0,
123 c_team_groups2: 0,
124 c_type: "Null".to_string(),
125 }
126 }
127}
128
129/// Represents separation constraints for the tournament.
130#[derive(Clone, Debug, Serialize, Deserialize)]
131pub struct SeparationConstraints {
132 /// Maximum allowed distance between occurrences.
133 pub c_max: i32,
134 /// Minimum required distance between occurrences.
135 pub c_min: i32,
136 /// Penalty value for violation.
137 pub c_penalty: i32,
138 /// Team group affected by the constraint.
139 pub c_team_groups: i32,
140 /// Type of constraint (description).
141 pub c_type: String,
142}
143
144impl SeparationConstraints {
145 /// Creates a new SeparationConstraints instance with default values.
146 pub fn new() -> Self {
147 Self {
148 c_max: 0,
149 c_min: 0,
150 c_penalty: 0,
151 c_team_groups: 0,
152 c_type: "Null".to_string(),
153 }
154 }
155}