mirror of
https://github.com/graphhopper/jsprit.git
synced 2020-01-24 07:45:05 +01:00
add javadoc to core.problem.Capacity
This commit is contained in:
parent
c55a6c54bd
commit
b36679452f
1 changed files with 44 additions and 45 deletions
|
|
@ -1,20 +1,18 @@
|
||||||
/*******************************************************************************
|
/*******************************************************************************
|
||||||
* Copyright (c) 2014 Stefan Schroeder.
|
* Copyright (C) 2014 Stefan Schroeder
|
||||||
*
|
*
|
||||||
* This library is free software; you can redistribute it and/or
|
* This library is free software; you can redistribute it and/or
|
||||||
* modify it under the terms of the GNU Lesser General Public
|
* modify it under the terms of the GNU Lesser General Public
|
||||||
* License as published by the Free Software Foundation; either
|
* License as published by the Free Software Foundation; either
|
||||||
* version 3.0 of the License, or (at your option) any later version.
|
* version 3.0 of the License, or (at your option) any later version.
|
||||||
*
|
*
|
||||||
* This library is distributed in the hope that it will be useful,
|
* This library is distributed in the hope that it will be useful,
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
*
|
* Lesser General Public License for more details.
|
||||||
* You should have received a copy of the GNU Lesser General Public
|
*
|
||||||
|
* You should have received a copy of the GNU Lesser General Public
|
||||||
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
|
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*
|
|
||||||
* Contributors:
|
|
||||||
* Stefan Schroeder - initial API and implementation
|
|
||||||
******************************************************************************/
|
******************************************************************************/
|
||||||
package jsprit.core.problem;
|
package jsprit.core.problem;
|
||||||
|
|
||||||
|
|
@ -33,8 +31,8 @@ public class Capacity {
|
||||||
*
|
*
|
||||||
* <p>Note that this assumes that capacity dimension can be added up.
|
* <p>Note that this assumes that capacity dimension can be added up.
|
||||||
*
|
*
|
||||||
* @param cap1
|
* @param cap1 capacity to be added up
|
||||||
* @param cap2
|
* @param cap2 capacity to be added up
|
||||||
* @return new capacity
|
* @return new capacity
|
||||||
* @throws NullPointerException if one of the args is null
|
* @throws NullPointerException if one of the args is null
|
||||||
|
|
||||||
|
|
@ -49,20 +47,20 @@ public class Capacity {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Subtracts cap2substract from cap and returns the resulting Capacity.
|
* Subtracts cap2subtract from cap and returns the resulting Capacity.
|
||||||
*
|
*
|
||||||
* @param cap
|
* @param cap capacity to be subtracted from
|
||||||
* @param cap2substract
|
* @param cap2subtract capacity to subtract
|
||||||
* @return new capacity
|
* @return new capacity
|
||||||
* @throws NullPointerException if one of the args is null
|
* @throws NullPointerException if one of the args is null
|
||||||
* @throws IllegalStateException if number of capacityDimensions of cap1 and cap2 are different (i.e. <code>cap1.getNuOfDimension() != cap2.getNuOfDimension()</code>).
|
* @throws IllegalStateException if number of capacityDimensions of cap1 and cap2 are different (i.e. <code>cap1.getNuOfDimension() != cap2.getNuOfDimension()</code>).
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public static Capacity subtract(Capacity cap, Capacity cap2substract){
|
public static Capacity subtract(Capacity cap, Capacity cap2subtract){
|
||||||
if(cap==null || cap2substract==null) throw new NullPointerException("arguments must not be null");
|
if(cap==null || cap2subtract==null) throw new NullPointerException("arguments must not be null");
|
||||||
Capacity.Builder capacityBuilder= Capacity.Builder.newInstance();
|
Capacity.Builder capacityBuilder= Capacity.Builder.newInstance();
|
||||||
for(int i=0;i<Math.max(cap.getNuOfDimensions(),cap2substract.getNuOfDimensions());i++){
|
for(int i=0;i<Math.max(cap.getNuOfDimensions(),cap2subtract.getNuOfDimensions());i++){
|
||||||
int dimValue = cap.get(i)-cap2substract.get(i);
|
int dimValue = cap.get(i)-cap2subtract.get(i);
|
||||||
capacityBuilder.addDimension(i, dimValue);
|
capacityBuilder.addDimension(i, dimValue);
|
||||||
}
|
}
|
||||||
return capacityBuilder.build();
|
return capacityBuilder.build();
|
||||||
|
|
@ -71,7 +69,7 @@ public class Capacity {
|
||||||
/**
|
/**
|
||||||
* Returns the inverted capacity, i.e. it multiplies all capacity dimensions with -1.
|
* Returns the inverted capacity, i.e. it multiplies all capacity dimensions with -1.
|
||||||
*
|
*
|
||||||
* @param cap2invert
|
* @param cap2invert capacity to be inverted
|
||||||
* @return inverted capacity
|
* @return inverted capacity
|
||||||
* @throws NullPointerException if one of the args is null
|
* @throws NullPointerException if one of the args is null
|
||||||
*/
|
*/
|
||||||
|
|
@ -91,9 +89,9 @@ public class Capacity {
|
||||||
*
|
*
|
||||||
* <p>If both nominator.get(i) and denominator.get(i) equal to 0, dimension i is ignored.
|
* <p>If both nominator.get(i) and denominator.get(i) equal to 0, dimension i is ignored.
|
||||||
* <p>If both capacities are have only dimensions with dimensionVal=0, it returns 0.0
|
* <p>If both capacities are have only dimensions with dimensionVal=0, it returns 0.0
|
||||||
* @param numerator
|
* @param numerator the numerator
|
||||||
* @param denominator
|
* @param denominator the denominator
|
||||||
* @return
|
* @return quotient
|
||||||
* @throws IllegalStateException if numerator.get(i) != 0 and denominator.get(i) == 0
|
* @throws IllegalStateException if numerator.get(i) != 0 and denominator.get(i) == 0
|
||||||
*/
|
*/
|
||||||
public static double divide(Capacity numerator, Capacity denominator){
|
public static double divide(Capacity numerator, Capacity denominator){
|
||||||
|
|
@ -118,8 +116,8 @@ public class Capacity {
|
||||||
/**
|
/**
|
||||||
* Makes a deep copy of Capacity.
|
* Makes a deep copy of Capacity.
|
||||||
*
|
*
|
||||||
* @param capacity
|
* @param capacity capacity to be copied
|
||||||
* @return
|
* @return copy
|
||||||
*/
|
*/
|
||||||
public static Capacity copyOf(Capacity capacity){
|
public static Capacity copyOf(Capacity capacity){
|
||||||
if(capacity == null) return null;
|
if(capacity == null) return null;
|
||||||
|
|
@ -156,9 +154,9 @@ public class Capacity {
|
||||||
* <p>Note that it automatically resizes dimensions according to index, i.e. if index=7 there are 8 dimensions.
|
* <p>Note that it automatically resizes dimensions according to index, i.e. if index=7 there are 8 dimensions.
|
||||||
* New dimensions then are initialized with 0
|
* New dimensions then are initialized with 0
|
||||||
*
|
*
|
||||||
* @param index
|
* @param index dimensionIndex
|
||||||
* @param dimValue
|
* @param dimValue dimensionValue
|
||||||
* @return
|
* @return this builder
|
||||||
*/
|
*/
|
||||||
public Builder addDimension(int index, int dimValue){
|
public Builder addDimension(int index, int dimValue){
|
||||||
if(index < dimensions.length){
|
if(index < dimensions.length){
|
||||||
|
|
@ -197,7 +195,7 @@ public class Capacity {
|
||||||
/**
|
/**
|
||||||
* copy constructor
|
* copy constructor
|
||||||
*
|
*
|
||||||
* @param capacity
|
* @param capacity capacity to be copied
|
||||||
*/
|
*/
|
||||||
Capacity(Capacity capacity){
|
Capacity(Capacity capacity){
|
||||||
this.dimensions = new int[capacity.getNuOfDimensions()];
|
this.dimensions = new int[capacity.getNuOfDimensions()];
|
||||||
|
|
@ -213,19 +211,21 @@ public class Capacity {
|
||||||
/**
|
/**
|
||||||
* Returns the number of specified capacity dimensions.
|
* Returns the number of specified capacity dimensions.
|
||||||
*
|
*
|
||||||
* @return
|
* @return noDimensions
|
||||||
*/
|
*/
|
||||||
public int getNuOfDimensions(){
|
public int getNuOfDimensions(){
|
||||||
return dimensions.length;
|
return dimensions.length;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns value of capacity-dimension with specified index.
|
* Returns value of capacity-dimension with specified index.
|
||||||
*
|
*
|
||||||
* <p>If capacity dimension does not exist, it returns 0 (rather than IndexOutOfBoundsException).
|
* <p>If capacity dimension does not exist, it returns 0 (rather than IndexOutOfBoundsException).
|
||||||
*
|
*
|
||||||
* @param index
|
* @param index dimension index of the capacity value to be retrieved
|
||||||
* @return
|
* @return the according dimension value
|
||||||
*/
|
*/
|
||||||
public int get(int index){
|
public int get(int index){
|
||||||
if(index<dimensions.length) return dimensions[index];
|
if(index<dimensions.length) return dimensions[index];
|
||||||
|
|
@ -235,8 +235,8 @@ public class Capacity {
|
||||||
/**
|
/**
|
||||||
* Returns true if this capacity is less or equal than the capacity toCompare, i.e. if none of the capacity dimensions > than the corresponding dimension in toCompare.
|
* Returns true if this capacity is less or equal than the capacity toCompare, i.e. if none of the capacity dimensions > than the corresponding dimension in toCompare.
|
||||||
*
|
*
|
||||||
* @param toCompare
|
* @param toCompare the capacity to compare
|
||||||
* @return
|
* @return true if this capacity is less or equal than toCompare
|
||||||
* @throws NullPointerException if one of the args is null
|
* @throws NullPointerException if one of the args is null
|
||||||
*/
|
*/
|
||||||
public boolean isLessOrEqual(Capacity toCompare){
|
public boolean isLessOrEqual(Capacity toCompare){
|
||||||
|
|
@ -250,8 +250,8 @@ public class Capacity {
|
||||||
/**
|
/**
|
||||||
* Returns true if this capacity is greater or equal than the capacity toCompare
|
* Returns true if this capacity is greater or equal than the capacity toCompare
|
||||||
*
|
*
|
||||||
* @param toCompare
|
* @param toCompare the capacity to compare
|
||||||
* @return
|
* @return true if this capacity is greater or equal than toCompare
|
||||||
* @throws NullPointerException if one of the args is null
|
* @throws NullPointerException if one of the args is null
|
||||||
|
|
||||||
*/
|
*/
|
||||||
|
|
@ -265,20 +265,19 @@ public class Capacity {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
StringBuilder sBuilder = new StringBuilder();
|
String string = "[noDimensions="+getNuOfDimensions()+"]";
|
||||||
sBuilder.append("[nuOfDimensions="+getNuOfDimensions()+"]");
|
for(int i=0;i<getNuOfDimensions();i++){
|
||||||
for(int i=0;i<getNuOfDimensions();i++){
|
string += "[[dimIndex="+i+"][dimValue="+dimensions[i]+"]]";
|
||||||
sBuilder.append("[[dimIndex="+i+"][dimValue="+dimensions[i]+"]]");
|
}
|
||||||
}
|
return string;
|
||||||
return sBuilder.toString();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Return the maximum, i.e. the maximum of each capacity dimension.
|
* Return the maximum, i.e. the maximum of each capacity dimension.
|
||||||
*
|
*
|
||||||
* @param cap1
|
* @param cap1 first capacity to compare
|
||||||
* @param cap2
|
* @param cap2 second capacity to compare
|
||||||
* @return
|
* @return capacity maximum of each capacity dimension
|
||||||
*/
|
*/
|
||||||
public static Capacity max(Capacity cap1, Capacity cap2) {
|
public static Capacity max(Capacity cap1, Capacity cap2) {
|
||||||
if(cap1 == null || cap2 == null) throw new IllegalArgumentException("arg must not be null");
|
if(cap1 == null || cap2 == null) throw new IllegalArgumentException("arg must not be null");
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue