xcsp3_rust/constraints/xconstraint_type.rs
1/*=============================================================================
2* parser for CSP instances represented in XCSP3 Format
3*
4* Copyright (c) 2023 xcsp.org (contact @ xcsp.org)
5*
6* Permission is hereby granted, free of charge, to any person obtaining a copy
7* of this software and associated documentation files (the "Software"), to deal
8* in the Software without restriction, including without limitation the rights
9* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10* copies of the Software, and to permit persons to whom the Software is
11* furnished to do so, subject to the following conditions:
12*
13* The above copyright notice and this permission notice shall be included in
14* all copies or substantial portions of the Software.
15*
16* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22* THE SOFTWARE.
23*=============================================================================
24*/
25
26/*
27* <p>@project_name: xcsp3-rust
28* </p>
29* <p>@author: luhan zhen
30* </p>
31* <p>@date: 2023/7/14 18:56
32* </p>
33* <p>@email: zhenlh20@mails.jlu.edu.cn
34* </p>
35* <p>@version: 1.0
36* </p>
37 * <p>@description: 1.0
38* </p>
39 */
40
41pub mod xcsp3_core {
42 use crate::constraints::xall_different::xcsp3_core::XAllDifferent;
43 use crate::constraints::xall_different_except::xcsp3_core::XAllDifferentExcept;
44 use crate::constraints::xall_equal::xcsp3_core::XAllEqual;
45 use crate::constraints::xcardinality::xcsp3_core::XCardinality;
46 use crate::constraints::xchannel::xcsp3_core::XChannel;
47 use crate::constraints::xcount::xcsp3_core::XCount;
48 use crate::constraints::xcumulative::xcsp3_core::XCumulative;
49 use crate::constraints::xelement::xcsp3_core::XElement;
50 use crate::constraints::xextension::xcsp3_core::XExtension;
51 use crate::constraints::xgroup::xcsp3_core::XGroup;
52 use crate::constraints::xinstantiation::xcsp3_core::XInstantiation;
53 use crate::constraints::xintension::xcsp3_core::XIntention;
54 use crate::constraints::xmax_min::xcsp3_core::XMaxMin;
55 use crate::constraints::xmdd::xcsp3_core::XMdd;
56 use crate::constraints::xn_values::xcsp3_core::XNValues;
57 use crate::constraints::xno_overlap::xcsp3_core::XNoOverlap;
58 use crate::constraints::xno_overlap_k_dimensional::xcsp3_core::XNoOverlapKDim;
59 use crate::constraints::xordered::xcsp3_core::XOrdered;
60 use crate::constraints::xregular::xcsp3_core::XRegular;
61 use crate::constraints::xslide::xcsp3_core::XSlide;
62 use crate::constraints::xstretch::xcsp3_core::XStretch;
63 use crate::constraints::xsum::xcsp3_core::XSum;
64 use crate::errors::xcsp3error::xcsp3_core::Xcsp3Error;
65 use std::fmt::{Display, Formatter};
66
67 // #[derive(Clone)]
68 pub enum XConstraintType<'a> {
69 XConstraintNone(Xcsp3Error),
70 XExtension(XExtension<'a>),
71 XAllDifferent(XAllDifferent<'a>),
72 XAllDifferentExcept(XAllDifferentExcept<'a>),
73 XInstantiation(XInstantiation<'a>),
74 XAllEqual(XAllEqual<'a>),
75 XOrdered(XOrdered<'a>),
76 XRegular(XRegular<'a>),
77 XMdd(XMdd<'a>),
78 XIntention(XIntention<'a>),
79 XGroup(XGroup<'a>),
80 XSum(XSum<'a>),
81 XMaximum(XMaxMin<'a>),
82 XMinimum(XMaxMin<'a>),
83 XElement(XElement<'a>),
84 XSlide(XSlide<'a>),
85 XCount(XCount<'a>),
86 XNValues(XNValues<'a>),
87 XCardinality(XCardinality<'a>),
88 XChannel(XChannel<'a>),
89 XCumulative(XCumulative<'a>),
90 XNoOverlap(XNoOverlap<'a>),
91 XStretch(XStretch<'a>),
92 XNoOverlapKDim(XNoOverlapKDim<'a>),
93 }
94
95 impl Display for XConstraintType<'_> {
96 fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
97 write!(f,"{}",
98 match self {
99 XConstraintType::XConstraintNone(e) => format!(
100 "XConstraintNone: there must be an error when parse this constraint. Error is {}",e
101 ),
102 XConstraintType::XStretch(c) => c.to_string(),
103 XConstraintType::XChannel(c) => c.to_string(),
104 XConstraintType::XCumulative(c) => c.to_string(),
105 XConstraintType::XNoOverlap(c) => c.to_string(),
106 XConstraintType::XExtension(c) => c.to_string(),
107 XConstraintType::XAllEqual(c) => c.to_string(),
108 XConstraintType::XAllDifferent(c) => c.to_string(),
109 XConstraintType::XAllDifferentExcept(c) => c.to_string(),
110 XConstraintType::XInstantiation(c) => c.to_string(),
111 XConstraintType::XOrdered(c) => c.to_string(),
112 XConstraintType::XRegular(c) => c.to_string(),
113 XConstraintType::XMdd(c) => c.to_string(),
114 XConstraintType::XIntention(c) => c.to_string(),
115 XConstraintType::XGroup(c) => c.to_string(),
116 XConstraintType::XSum(c) => c.to_string(),
117 XConstraintType::XMinimum(c) => c.to_string(),
118 XConstraintType::XMaximum(c) => c.to_string(),
119 XConstraintType::XElement(c) => c.to_string(),
120 XConstraintType::XSlide(c) => c.to_string(),
121 XConstraintType::XCount(c) => c.to_string(),
122 XConstraintType::XNValues(c) => c.to_string(),
123 XConstraintType::XCardinality(c) => c.to_string(),
124 XConstraintType::XNoOverlapKDim(c) => c.to_string(),
125 }
126 )
127 }
128 }
129
130 // impl XConstraintType<'_> {
131 // pub fn to_string(&self) -> String {
132 // match self {
133 // XConstraintType::XConstraintNone(e) => format!(
134 // "XConstraintNone: there must be an error when parse this constraint. Error is {}",e.to_string()
135 // ),
136 // XConstraintType::XExtension(c) => c.to_string(),
137 // XConstraintType::XAllEqual(c) => c.to_string(),
138 // XConstraintType::XAllDifferent(c) => c.to_string(),
139 // XConstraintType::XAllDifferentExcept(c) => c.to_string(),
140 // XConstraintType::XInstantiation(c) => c.to_string(),
141 // XConstraintType::XOrdered(c) => c.to_string(),
142 // XConstraintType::XRegular(c) => c.to_string(),
143 // XConstraintType::XMdd(c) => c.to_string(),
144 // XConstraintType::XIntention(c) => c.to_string(),
145 // XConstraintType::XGroup(c) => c.to_string(),
146 // XConstraintType::XSum(c) => c.to_string(),
147 // XConstraintType::XMinimum(c) => c.to_string(),
148 // XConstraintType::XMaximum(c) => c.to_string(),
149 //
150 // }
151 // }
152 // }
153}