Hi everyone.
I don't know how many of you have read this thread (apart from Daved) there are TOO many posts.Anyway, i have a problem( the last one).This last code:
Code:
int not_covered;
for (int n=1; n <= NumberRuns; n++){
while (!aSol -> is_complete()) {
for (int i = 0; i < instance -> n_cols ; i++) {
if(aSol -> is_added[i]){
k[i] = -1;}
else{
not_covered = 0;
for (int j = 0; j < (instance->covers)[i].size(); j++) {
int aRow = (instance->covers)[i][j];
if (!aSol -> is_covered[aRow]) {
// cout<<"not covered "<<endl;
not_covered++;
}
}
k[i] = (double) (not_covered)*1000.0/(double) (instance -> cost[i]);
}
}
aSol -> add_column(GetMax(k,instance->n_cols));
}
random_shuffle (aSol -> selected_columns.begin(), aSol -> selected_columns.end() );
aSol -> selected_columns.erase ( aSol -> selected_columns.begin(),aSol -> selected_columns.begin() + aSol -> selected_columns.size()/2 );
gives me a first solution.Not the optimal but quite close to it.BUT it cannot compute another one because of this
Code:
aSol -> selected_columns.erase ( aSol -> selected_columns.begin(),aSol -> selected_columns.begin() + aSol -> selected_columns.size()/2 );
. What this line do, is erase the columns of the solution,WITHOUT erasing the rows that they cover.That's why it cannot compute another solution. I want to erase the half of the columns and the rows that they cover. I thought of writing a function like this one:
Code:
void Solution::add_column(int i) {
selected_columns.push_back(i);
obj_value = obj_value + (instance->cost)[i];
is_added[i] = true;
for (int j = 0; j < (instance->covers)[i].size(); j++) {
int aRow = (instance->covers)[i][j];
if (!is_covered[aRow]) {
n_covered++;
is_covered[aRow] = true;
}
}
}
which will be called let's say rmv_column and it will do the opposite of add_column and then run it in a for loop for the half of the columns of the solution.But i don't know how it woud be the
Code:
selected_columns.push_back(i);
part and if i should use also the erase function i already have and how..Or if you could suggest me another way,easier..This is the only thing it is left to do.
Please any hint would be really really helpful..