001 /* 002 * Licensed to the Apache Software Foundation (ASF) under one or more 003 * contributor license agreements. See the NOTICE file distributed with 004 * this work for additional information regarding copyright ownership. 005 * The ASF licenses this file to You under the Apache License, Version 2.0 006 * (the "License"); you may not use this file except in compliance with 007 * the License. You may obtain a copy of the License at 008 * 009 * http://www.apache.org/licenses/LICENSE-2.0 010 * 011 * Unless required by applicable law or agreed to in writing, software 012 * distributed under the License is distributed on an "AS IS" BASIS, 013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 014 * See the License for the specific language governing permissions and 015 * limitations under the License. 016 */ 017 package org.apache.commons.math3.optim.univariate; 018 019 import org.apache.commons.math3.optim.OptimizationData; 020 import org.apache.commons.math3.exception.NumberIsTooLargeException; 021 import org.apache.commons.math3.exception.OutOfRangeException; 022 023 /** 024 * Search interval and (optional) start value. 025 * <br/> 026 * Immutable class. 027 * 028 * @version $Id$ 029 * @since 3.1 030 */ 031 public class SearchInterval implements OptimizationData { 032 /** Lower bound. */ 033 private final double lower; 034 /** Upper bound. */ 035 private final double upper; 036 /** Start value. */ 037 private final double start; 038 039 /** 040 * @param lo Lower bound. 041 * @param hi Upper bound. 042 * @param init Start value. 043 * @throws NumberIsTooLargeException if {@code lo >= hi}. 044 * @throws OutOfRangeException if {@code init < lo} or {@code init > hi}. 045 */ 046 public SearchInterval(double lo, 047 double hi, 048 double init) { 049 if (lo >= hi) { 050 throw new NumberIsTooLargeException(lo, hi, false); 051 } 052 if (init < lo || 053 init > hi) { 054 throw new OutOfRangeException(init, lo, hi); 055 } 056 057 lower = lo; 058 upper = hi; 059 start = init; 060 } 061 062 /** 063 * @param lo Lower bound. 064 * @param hi Upper bound. 065 * @throws NumberIsTooLargeException if {@code lo >= hi}. 066 */ 067 public SearchInterval(double lo, 068 double hi) { 069 this(lo, hi, 0.5 * (lo + hi)); 070 } 071 072 /** 073 * Gets the lower bound. 074 * 075 * @return the lower bound. 076 */ 077 public double getMin() { 078 return lower; 079 } 080 /** 081 * Gets the upper bound. 082 * 083 * @return the upper bound. 084 */ 085 public double getMax() { 086 return upper; 087 } 088 /** 089 * Gets the start value. 090 * 091 * @return the start value. 092 */ 093 public double getStartValue() { 094 return start; 095 } 096 }