cz.cvut.felk.cig.jcop.problem.knapsack.RemoveOperation Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of jcop Show documentation
Show all versions of jcop Show documentation
Java Combinatorial Optimization Platform
The newest version!
/*
* Copyright © 2010 by Ondrej Skalicka. All Rights Reserved
*/
package cz.cvut.felk.cig.jcop.problem.knapsack;
import cz.cvut.felk.cig.jcop.problem.BaseReversibleOperation;
import cz.cvut.felk.cig.jcop.problem.Configuration;
import cz.cvut.felk.cig.jcop.problem.OperationHistory;
import java.util.List;
/**
* Removes item from knapsack
*
* @author Ondrej Skalicka
*/
public class RemoveOperation extends BaseReversibleOperation {
/**
* Item to be removed from knapsack.
*/
protected KnapsackItem knapsackItem;
/**
* Creates new RemoveOperation associated with knapsackItem
*
* @param knapsackItem item to associate operation with
*/
public RemoveOperation(KnapsackItem knapsackItem) {
this.knapsackItem = knapsackItem;
}
public Configuration execute(Configuration configuration) {
List newConfiguration = configuration.asList();
newConfiguration.set(this.knapsackItem.getIndex(), 0);
return new Configuration(newConfiguration, new OperationHistory(this, configuration.getOperationHistory()));
}
@Override
public String toString() {
return "RemoveOperation{" +
"knapsackItem=" + knapsackItem +
'}';
}
}