001    package edu.nrao.sss.model.project.scheduling.constraint;
002    
003    
004    import java.util.List;
005    
006    import javax.xml.bind.annotation.XmlRootElement;
007    
008    
009    
010    /**
011     * Represents a minimum elevation of the target constraint.
012     * @author slovelan
013     */
014    @XmlRootElement
015    public class ConstraintPositionElevation extends Constraint {
016            
017            private static final float DEFAULT_VALUE = -1;
018            
019            //Elevation of the target source.
020            private float elevation = DEFAULT_VALUE;
021            
022            //-------------------------------------------------------------------------
023            //                         Construction
024            //-------------------------------------------------------------------------
025            
026            public ConstraintPositionElevation(){
027                    constraintType = ConstraintType.POSITION_ELEVATION;
028            }
029            
030            public ConstraintPositionElevation( ConstraintPositionElevation cpe ){
031                    super( cpe );
032            }
033            
034            public Object getValue(){
035                    return new Float( elevation );
036            }
037            
038            //-------------------------------------------------------------------------
039            //                Removing the API Constraint
040            //-------------------------------------------------------------------------
041            
042            public void reset(){
043                    elevation = DEFAULT_VALUE;
044            }
045            
046            public boolean isSpecified(){
047                    boolean specified = true;
048                    if ( elevation == DEFAULT_VALUE ){
049                            specified = false;
050                    }
051                    return specified;
052            }
053    
054            //-------------------------------------------------------------------------
055            //                      Elevation
056            //-------------------------------------------------------------------------
057            
058            public float getElevation(){
059                    return elevation;
060            }
061            
062            public void setElevation( float elevation ){
063                    if ( elevation >= 0 && elevation < Math.PI ){
064                            this.elevation = elevation;
065                    }
066                    else {
067                            elevation = 0;
068                    }
069            }
070            
071    
072            //--------------------------------------------------------------------------------
073            //                  Probability
074            //--------------------------------------------------------------------------------
075    
076            /**
077             * Returns the sign of the elevation of the target as the probability of
078             * success of the scheduling block or returns 0 if the elevation does not
079             * meet the minimum requirement in this constraint.
080             * @return a ConstraintProbability indicating the probability of success
081             *         for the constraint.
082             */
083            
084            public ConstraintProbability getProbabilitySuccess( List<Constraint> constraints ){
085    
086                    ConstraintProbability result = new ConstraintProbability();
087                    result.setConstraintType( constraintType );
088                    result.setProbabilitySuccess( ConstraintProbability.SUCCESS );
089                    
090                    if ( isSpecified() ){
091                            Constraint sbConstraint = getConstraint( constraints );
092                            if ( sbConstraint instanceof ConstraintPositionElevation ){
093                                    ConstraintPositionElevation otherConstraint = (ConstraintPositionElevation) sbConstraint;
094                                    double otherElevation = otherConstraint.getElevation();
095                                    double otherSign = Math.sin( otherElevation );
096                                    double thisSign = Math.sin( elevation );
097                                    //The elevation did not meet the minimum requirement so designate it
098                                    //as a failure.
099                                    if ( thisSign > otherSign ){
100                                            result.setProbabilitySuccess( ConstraintProbability.FAILURE );
101                                            result.setMessage( "The current elevation of "+otherElevation+" does not meet minimum elevation requirements" );
102                                    }
103                                    //The elevation met the minimum requirement so designate the sign
104                                    //of the elevation as a measure of success.
105                                    else {
106                                            result.setProbabilitySuccess( (float)otherSign );
107                                    }
108                            }
109                            else {
110                                    result.setMessage( ConstraintProbability.NO_CONSTRAINT_SB );
111                            }
112                    }
113                    else {
114                            result.setMessage( ConstraintProbability.NO_CONSTRAINT_OPERATING );
115                    }
116                    return result;
117            }
118            
119            
120            
121            
122    }