@@ -29,8 +29,8 @@ void letturamat(int **m, FILE *fin, int r, int c);
29
29
void calculateOF (Sol * temp , Instances * in );
30
30
int check (Sol * temp , Instances * in );
31
31
int check1 (Sol * temp , Instances * in );
32
- int check2 (Sol * temp , Instances * in ); //TODO
33
- int check3 (Sol * temp , Instances * in ); //TODO
32
+ int check2 (Sol * temp , Instances * in );
33
+ int check3 (Sol * temp , Instances * in );
34
34
Sol solGen (Sol * temp , Instances * in ); //TODO
35
35
36
36
int main (int argc , char * argv [])
@@ -178,36 +178,49 @@ void calculateOF(Sol *temp, Instances *in)
178
178
temp -> gain = (gain - cost );
179
179
}
180
180
181
+ //int check(Sol *temp, Instances *in)
182
+ //// Returns 1 if temp is feasible, 0 otherwise.
183
+ //{
184
+ // int c, q;
185
+ // int con2=0;
186
+ //
187
+ // //Constraint (2)
188
+ // for(q=0; q<in->Q; q++)
189
+ // {
190
+ // con2=0;
191
+ // for(c=0; c<in->C; c++)
192
+ // {
193
+ // con2+=temp->Xcq[c][q];
194
+ // }
195
+ // if(con2>1)
196
+ // {
197
+ // return 0;
198
+ // }
199
+ // }
200
+ //
201
+ // //Constraint (3)
202
+ // if(temp->mem > in->M)
203
+ // {
204
+ // return 0;
205
+ // }
206
+ // return 1;
207
+ //}
208
+
181
209
int check (Sol * temp , Instances * in )
182
210
// Returns 1 if temp is feasible, 0 otherwise.
183
211
{
184
- int c , q ;
185
- int con2 = 0 ;
186
-
187
- //Constraint (2)
188
- for (q = 0 ; q < in -> Q ; q ++ )
189
- {
190
- con2 = 0 ;
191
- for (c = 0 ; c < in -> C ; c ++ )
192
- {
193
- con2 += temp -> Xcq [c ][q ];
194
- }
195
- if (con2 > 1 )
196
- {
197
- return 0 ;
198
- }
199
- }
200
-
201
- //Constraint (3)
202
- if (temp -> mem > in -> M )
203
- {
212
+ if (check1 (temp ,in ) > 0 ||
213
+ check2 (temp ,in ) > 0 ||
214
+ check3 (temp ,in ) > 0 ) {
215
+ return 1 ;
216
+ } else {
204
217
return 0 ;
205
218
}
206
- return 1 ;
207
219
}
208
220
209
221
int check1 (Sol * temp , Instances * in )
210
222
// check constraint 1
223
+ // returns the number of indexes that should be present and are not, scaled by a factor.
211
224
{
212
225
int c , q , i ;
213
226
int p1 = 0 ;
@@ -218,7 +231,7 @@ int check1(Sol *temp, Instances *in)
218
231
if (temp -> Xcq [c ][q ] == 1 ) {
219
232
for (i = 0 ; i < in -> I ; i ++ ) {
220
233
if (in -> Eci [c ][i ] == 1 && temp -> Zi == 0 ) {
221
- pi ++ ;
234
+ p1 ++ ;
222
235
}
223
236
}
224
237
}
@@ -231,6 +244,38 @@ int check1(Sol *temp, Instances *in)
231
244
232
245
int check2 (Sol * temp , Instances * in )
233
246
// check constraint 2
247
+ // returns 0 if every query has at most one configuration associated, otherwise it returns a value grater then 0, scaled by a factor.
234
248
{
249
+ int q , c ;
250
+ int p2 , p2max = 0 ;
251
+ //TODO: aggiungere fattore di scalamento
235
252
253
+ for (q = 0 ; q < in -> Q ; q ++ )
254
+ {
255
+ p2 = 0 ;
256
+ for (c = 0 ; c < in -> C ; c ++ )
257
+ {
258
+ p2 += temp -> Xcq [c ][q ];
259
+ }
260
+ if (p2 > p2max )
261
+ {
262
+ p2max = p2 ;
263
+ }
264
+ }
265
+
266
+ return p2max - 1 ;
267
+ }
268
+
269
+ int check3 (Sol * temp , Instances * in )
270
+ // check constraint 3
271
+ // returns 0 if limit M is not exceeded, otherwise it returns the excess amount, scaled by a factor.
272
+ {
273
+ //TODO: aggiungere fattore di scalamento
274
+
275
+ if (temp -> mem > in -> M )
276
+ {
277
+ return temp -> mem - in -> M ;
278
+ }
279
+
280
+ return 0 ;
236
281
}
0 commit comments