1 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2 /*                                                                           */
3 /*                  This file is part of the program and library             */
4 /*         SCIP --- Solving Constraint Integer Programs                      */
5 /*                                                                           */
6 /*    Copyright (C) 2002-2021 Konrad-Zuse-Zentrum                            */
7 /*                            fuer Informationstechnik Berlin                */
8 /*                                                                           */
9 /*  SCIP is distributed under the terms of the ZIB Academic License.         */
10 /*                                                                           */
11 /*  You should have received a copy of the ZIB Academic License              */
12 /*  along with SCIP; see the file COPYING. If not visit scipopt.org.         */
13 /*                                                                           */
14 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
15 
16 /**@file   pattern.h
17  * @brief  pattern data for ringpacking problem
18  * @author Benjamin Mueller
19  */
20 
21 /*---+----1----+----2----+----3----+----4----+----5----+----6----+----7----+----8----+----9----+----0----+----1----+----2*/
22 
23 #ifndef __SCIP_PATTERN__
24 #define __SCIP_PATTERN__
25 
26 #include "scip/scip.h"
27 
28 /*
29  * data structures
30  */
31 
32 enum SCIP_Packable
33 {
34    SCIP_PACKABLE_NO      = 0,                  /**< pattern is definitely packable */
35    SCIP_PACKABLE_YES     = 1,                  /**< pattern is definitely not packable */
36    SCIP_PACKABLE_UNKNOWN = 2                   /**< it is unknown whether pattern is packable */
37 };
38 typedef enum SCIP_Packable SCIP_PACKABLE;
39 
40 enum SCIP_Patterntype
41 {
42    SCIP_PATTERNTYPE_CIRCULAR    = 0,           /**< circular pattern */
43    SCIP_PATTERNTYPE_RECTANGULAR = 1            /**< rectangular pattern */
44 };
45 typedef enum SCIP_Patterntype SCIP_PATTERNTYPE;
46 
47 struct SCIP_Pattern
48 {
49    BMS_BLKMEM*           blkmem;             /**< block memory */
50    SCIP_PATTERNTYPE      patterntype;        /**< pattern type */
51    SCIP_PACKABLE         packable;           /**< packable status */
52    SCIP_Real*            xs;                 /**< array containing the x-coordinate of each element */
53    SCIP_Real*            ys;                 /**< array containing the y-coordinate of each element */
54    int*                  types;              /**< array storing the type of each element */
55    int                   size;               /**< size of types, xs, and ys arrays */
56    int                   nelems;             /**< number of elements stored */
57    int                   nlocks;             /**< number of locks */
58    int                   type;               /**< type of the boundary circle */
59 };
60 typedef struct SCIP_Pattern SCIP_PATTERN;
61 
62 /** creates an empty circular pattern */
63 SCIP_RETCODE SCIPpatternCreateCircular(
64    SCIP*                 scip,               /**< SCIP data structure */
65    SCIP_PATTERN**        pattern,            /**< pointer to store pattern */
66    int                   type                /**< circle type (not needed for rectangular patterns) */
67    );
68 
69 /** creates an empty rectangular pattern */
70 SCIP_RETCODE SCIPpatternCreateRectangular(
71    SCIP*                 scip,               /**< SCIP data structure */
72    SCIP_PATTERN**        pattern             /**< pointer to store pattern */
73    );
74 
75 /** captures a pattern */
76 void SCIPpatternCapture(
77    SCIP_PATTERN*         pattern             /**< pattern */
78    );
79 
80 /* frees a pattern */
81 void SCIPpatternRelease(
82    SCIP*                 scip,               /**< SCIP data structure */
83    SCIP_PATTERN**        pattern             /**< pointer to free pattern */
84    );
85 
86 /** copies a pattern */
87 SCIP_RETCODE SCIPpatternCopy(
88    SCIP*                 scip,               /**< SCIP data structure */
89    SCIP_PATTERN*         pattern,            /**< pattern to copy */
90    SCIP_PATTERN**        copy                /**< pointer to store the copy */
91    );
92 
93 /** adds an element of a given type to a pattern; packable status does not change */
94 SCIP_RETCODE SCIPpatternAddElement(
95    SCIP_PATTERN*         pattern,            /**< pattern */
96    int                   type,               /**< element of a given type */
97    SCIP_Real             x,                  /**< x-coordinate (SCIP_INVALID: unknown) */
98    SCIP_Real             y                   /**< y-coordinate (SCIP_INVALID: unknown) */
99    );
100 
101 /** removes the last k elements */
102 void SCIPpatternRemoveLastElements(
103    SCIP_PATTERN*         pattern,            /**< pattern */
104    int                   k                   /**< number of elements to remove */
105    );
106 
107 /** returns the total number of elements of a given type in the pattern */
108 int SCIPpatternGetNElemens(
109    SCIP_PATTERN*         pattern             /**< pattern */
110    );
111 
112 /** returns the type of the i-th element */
113 int SCIPpatternGetElementType(
114    SCIP_PATTERN*         pattern,            /**< pattern */
115    int                   i                   /**< i-th element */
116    );
117 
118 /** returns the total number of elements of a given type */
119 int SCIPpatternCountElements(
120    SCIP_PATTERN*         pattern,            /**< pattern */
121    int                   type                /**< type */
122    );
123 
124 /** returns the x-coordinate of an element */
125 SCIP_Real SCIPpatternGetElementPosX(
126    SCIP_PATTERN*         pattern,            /**< pattern */
127    int                   elem                /**< index of the element */
128    );
129 
130 /** returns the y-coordinate of an element */
131 SCIP_Real SCIPpatternGetElementPosY(
132    SCIP_PATTERN*         pattern,            /**< pattern */
133    int                   elem                /**< index of the element */
134    );
135 
136 /** sets the (x,y) position of an element */
137 void SCIPpatternSetElementPos(
138    SCIP_PATTERN*         pattern,            /**< pattern */
139    int                   elem,               /**< index of the element */
140    SCIP_Real             x,                  /**< x-coordinate */
141    SCIP_Real             y                   /**< y-coordinate */
142    );
143 
144 /** returns the type of a pattern */
145 SCIP_PATTERNTYPE SCIPpatternGetPatternType(
146    SCIP_PATTERN*         pattern             /**< pattern */
147    );
148 
149 /** returns the type of the boundary circle
150  *
151  * @note this function can only be called for circular patterns
152  */
153 int SCIPpatternGetCircleType(
154    SCIP_PATTERN *pattern             /**< pattern */
155 );
156 
157 /** sets the type of the boundary circle
158  *
159  * @note this function can only be called for circular patterns
160  */
161 void SCIPpatternSetType(
162    SCIP_PATTERN*         pattern,            /**< pattern */
163    int                   type                /**< type */
164    );
165 
166 /** returns the packable status of a pattern */
167 SCIP_PACKABLE SCIPpatternGetPackableStatus(
168    SCIP_PATTERN*         pattern             /**< pattern */
169    );
170 
171 /** sets the packable status of a pattern */
172 void SCIPpatternSetPackableStatus(
173    SCIP_PATTERN*         pattern,            /**< pattern */
174    SCIP_PACKABLE         packable            /**< packable status */
175    );
176 
177 #endif /* __SCIP_PATTERN__ */
178