@@ -51,7 +51,22 @@ def __init__(self, model: Model) -> None:
5151 def clean_cached_properties (self ) -> None :
5252 """Clear the cache for all cached properties of an object"""
5353
54- for cached_prop in ["flat_vars" , "flat_cons" , "sol" , "dual" ]:
54+ for cached_prop in [
55+ "flat_vars" ,
56+ "flat_cons" ,
57+ "sol" ,
58+ "dual" ,
59+ "vlabels" ,
60+ "clabels" ,
61+ "A" ,
62+ "c" ,
63+ "b" ,
64+ "sense" ,
65+ "lb" ,
66+ "ub" ,
67+ "vtypes" ,
68+ "Q" ,
69+ ]:
5570 # check existence of cached_prop without creating it
5671 if cached_prop in self .__dict__ :
5772 delattr (self , cached_prop )
@@ -66,13 +81,13 @@ def flat_cons(self) -> pd.DataFrame:
6681 m = self ._parent
6782 return m .constraints .flat
6883
69- @property
84+ @cached_property
7085 def vlabels (self ) -> ndarray :
7186 """Vector of labels of all non-missing variables."""
7287 df : pd .DataFrame = self .flat_vars
7388 return create_vector (df .key , df .labels , - 1 )
7489
75- @property
90+ @cached_property
7691 def vtypes (self ) -> ndarray :
7792 """Vector of types of all non-missing variables."""
7893 m = self ._parent
@@ -93,7 +108,7 @@ def vtypes(self) -> ndarray:
93108 ds = df .set_index ("key" ).labels .map (ds )
94109 return create_vector (ds .index , ds .to_numpy (), fill_value = "" )
95110
96- @property
111+ @cached_property
97112 def lb (self ) -> ndarray :
98113 """Vector of lower bounds of all non-missing variables."""
99114 df : pd .DataFrame = self .flat_vars
@@ -123,21 +138,21 @@ def dual(self) -> ndarray:
123138 )
124139 return create_vector (df .key , df .dual , fill_value = np .nan )
125140
126- @property
141+ @cached_property
127142 def ub (self ) -> ndarray :
128143 """Vector of upper bounds of all non-missing variables."""
129144 df : pd .DataFrame = self .flat_vars
130145 return create_vector (df .key , df .upper )
131146
132- @property
147+ @cached_property
133148 def clabels (self ) -> ndarray :
134149 """Vector of labels of all non-missing constraints."""
135150 df : pd .DataFrame = self .flat_cons
136151 if df .empty :
137152 return np .array ([], dtype = int )
138153 return create_vector (df .key , df .labels , fill_value = - 1 )
139154
140- @property
155+ @cached_property
141156 def A (self ) -> csc_matrix | None :
142157 """Constraint matrix of all non-missing constraints and variables."""
143158 m = self ._parent
@@ -146,19 +161,19 @@ def A(self) -> csc_matrix | None:
146161 A : csc_matrix = m .constraints .to_matrix (filter_missings = False )
147162 return A [self .clabels ][:, self .vlabels ]
148163
149- @property
164+ @cached_property
150165 def sense (self ) -> ndarray :
151166 """Vector of senses of all non-missing constraints."""
152167 df : pd .DataFrame = self .flat_cons
153168 return create_vector (df .key , df .sign .astype (np .dtype ("<U1" )), fill_value = "" )
154169
155- @property
170+ @cached_property
156171 def b (self ) -> ndarray :
157172 """Vector of right-hand-sides of all non-missing constraints."""
158173 df : pd .DataFrame = self .flat_cons
159174 return create_vector (df .key , df .rhs )
160175
161- @property
176+ @cached_property
162177 def c (self ) -> ndarray :
163178 """Vector of objective coefficients of all non-missing variables."""
164179 m = self ._parent
@@ -171,7 +186,7 @@ def c(self) -> ndarray:
171186 shape : int = self .flat_vars .key .max () + 1
172187 return create_vector (vars , ds .coeffs , fill_value = 0.0 , shape = shape )
173188
174- @property
189+ @cached_property
175190 def Q (self ) -> csc_matrix | None :
176191 """Matrix objective coefficients of quadratic terms of all non-missing variables."""
177192 m = self ._parent
0 commit comments