Coverage Report - net.sourceforge.combean.graph.alg.lp.EdgesAsLPVariableSequence
 
Classes in this File Line Coverage Branch Coverage Complexity
EdgesAsLPVariableSequence
88%
22/25
67%
4/6
1,5
 
 1  
 /*
 2  
     This file is part of Combean.
 3  
 
 4  
     Combean is free software; you can redistribute it and/or modify
 5  
     it under the terms of the GNU General Public License as published by
 6  
     the Free Software Foundation; either version 2 of the License, or
 7  
     (at your option) any later version.
 8  
 
 9  
     Combean is distributed in the hope that it will be useful,
 10  
     but WITHOUT ANY WARRANTY; without even the implied warranty of
 11  
     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 12  
     GNU General Public License for more details.
 13  
 
 14  
     You should have received a copy of the GNU General Public License
 15  
     along with Combean; if not, write to the Free Software
 16  
     Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 17  
 */
 18  
 /*
 19  
  * Created on 02.09.2005
 20  
  *
 21  
  */
 22  
 package net.sourceforge.combean.graph.alg.lp;
 23  
 
 24  
 import net.sourceforge.combean.interfaces.graph.Edge;
 25  
 import net.sourceforge.combean.interfaces.graph.containers.doubleval.FixedDoubleEdgeMap;
 26  
 import net.sourceforge.combean.interfaces.graph.prop.GlobalNumberedEdgesGraphProp;
 27  
 import net.sourceforge.combean.interfaces.mathprog.lp.LPVariable;
 28  
 import net.sourceforge.combean.interfaces.mathprog.lp.model.LPVariableSequence;
 29  
 import net.sourceforge.combean.mathprog.lp.DoubleLPVariable;
 30  
 import net.sourceforge.combean.mathprog.lp.model.AbstractLPVariableSequence;
 31  
 
 32  
 /**
 33  
  * An LPVariableSequence which contains one variable per edge in a graph
 34  
  * with numbered edges.
 35  
  * 
 36  
  * @author schickin
 37  
  *
 38  
  */
 39  
 public class EdgesAsLPVariableSequence extends AbstractLPVariableSequence
 40  
 implements LPVariableSequence {
 41  
     
 42  30
     private GlobalNumberedEdgesGraphProp numberedEdges = null;
 43  
     
 44  30
     private FixedDoubleEdgeMap edgeCost = null;
 45  30
     private FixedDoubleEdgeMap edgeUpperBound = null;
 46  30
     private FixedDoubleEdgeMap edgeLowerBound = null;
 47  
 
 48  
     /**
 49  
      * Constructor
 50  
      * 
 51  
      * @param numberedEdges the graph for which the edges shall be turned
 52  
      * into LP variables.
 53  
      */
 54  
     public EdgesAsLPVariableSequence(String offsetId,
 55  
             GlobalNumberedEdgesGraphProp numberedEdges) {
 56  30
         super(offsetId);
 57  
         
 58  30
         this.numberedEdges = numberedEdges;
 59  30
     }
 60  
 
 61  
     /* (non-Javadoc)
 62  
      * @see net.sourceforge.combean.interfaces.mathprog.lp.model.LPConditionSequence#getLength()
 63  
      */
 64  
     public int getNumVars() {
 65  30
         return this.numberedEdges.getNumEdges();
 66  
     }
 67  
 
 68  
     /* (non-Javadoc)
 69  
      * @see net.sourceforge.combean.interfaces.mathprog.lp.model.LPVariableSequence#getLPVariable(int)
 70  
      */
 71  
     public LPVariable getLPVariable(int localColumn) {
 72  150
         Edge e = this.numberedEdges.getEdge(localColumn);
 73  
 
 74  150
         double coeff = 0;
 75  150
         if (this.edgeCost != null) {
 76  150
             coeff = this.edgeCost.getDouble(e);
 77  
         }
 78  
         
 79  150
         double lower = 0;
 80  150
         if (this.edgeLowerBound != null) {
 81  0
             lower = this.edgeLowerBound.getDouble(e);
 82  
         }
 83  
         
 84  150
         double upper = Double.POSITIVE_INFINITY;
 85  150
         if (this.edgeUpperBound != null) {
 86  135
             upper = this.edgeUpperBound.getDouble(e);
 87  
         }
 88  
         
 89  150
         return new DoubleLPVariable(getVarOffsetId() + localColumn,
 90  
                 coeff, lower, upper);
 91  
     }
 92  
     
 93  
     /**
 94  
      * @param edgeCost The edgeCost to set.
 95  
      */
 96  
     public final void setEdgeCost(FixedDoubleEdgeMap edgeCost) {
 97  30
         this.edgeCost = edgeCost;
 98  30
     }
 99  
     
 100  
     /**
 101  
      * @param edgeLowerBound The edgeLowerBound to set.
 102  
      */
 103  
     public final void setEdgeLowerBound(FixedDoubleEdgeMap edgeLowerBound) {
 104  0
         this.edgeLowerBound = edgeLowerBound;
 105  0
     }
 106  
     
 107  
     /**
 108  
      * @param edgeUpperBound The edgeUpperBound to set.
 109  
      */
 110  
     public final void setEdgeUpperBound(FixedDoubleEdgeMap edgeUpperBound) {
 111  27
         this.edgeUpperBound = edgeUpperBound;
 112  27
     }
 113  
 }