org.jamesframework.core.search.algo.vns.VNDFactory Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of james-core Show documentation
Show all versions of james-core Show documentation
The James core module is part of the James framework for optimization
using local search metaheuristics in Java. The core contains general
components to model problems, objectives and constraints, as well as
generic algorithms to solve the problems. Moreover, the core provides
implementations of specific utilities for subset selection.
// Copyright 2014 Herman De Beukelaer
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package org.jamesframework.core.search.algo.vns;
import java.util.List;
import org.jamesframework.core.problems.Problem;
import org.jamesframework.core.problems.solutions.Solution;
import org.jamesframework.core.search.NeighbourhoodSearch;
import org.jamesframework.core.search.neigh.Neighbourhood;
import org.jamesframework.core.util.LocalSearchFactory;
/**
* A VND factory creates a variable neighbourhood descent search, where the list of neighbourhoods to apply are
* set upon construction of the factory. By default, variable neighbourhood search uses a VND factory to generate
* VND searches that modify the solution obtained by randomly sampling a neighbour of the current solution using
* one of the shaking neighbourhoods.
*
* @param solution type of modified solutions, required to extend {@link Solution}
* @author Herman De Beukelaer
*/
public class VNDFactory implements LocalSearchFactory {
// applied neighbourhoods
List> neighs;
/**
* Create a new VND factory, given the list of neighbourhoods to apply.
* Note that neighs
can not be null
nor empty,
* and can not contain any null
elements.
*
* @param neighs neighbourhoods applied by VND
* @throws NullPointerException if neighs
is null
or contains any
* null
elements
* @throws IllegalArgumentException if neighs
is empty
*/
public VNDFactory(List> neighs){
// check neighbourhoods
if(neighs == null){
throw new NullPointerException("Can not create VND factory: list of neighbourhoods can not be null.");
}
for(Neighbourhood n : neighs){
if(n == null){
throw new NullPointerException("Can not create VND factory: list of neighbourhoods can not contain"
+ " any null elements.");
}
}
if(neighs.isEmpty()){
throw new IllegalArgumentException("Can not create VND factory: list of neighbourhoods can not be empty.");
}
// ok
this.neighs = neighs;
}
/**
* Create a VND search to solve the given problem, using the list of neighbourhoods
* set at construction of the factory.
*
* @param problem problem to solve
* @return VND search
*/
@Override
public NeighbourhoodSearch create(Problem problem){
return new VariableNeighbourhoodDescent<>(problem, neighs);
}
}