001 package edu.nrao.sss.model.project.scheduling.constraint; 002 003 import javax.xml.bind.annotation.XmlRootElement; 004 005 import java.util.List; 006 007 008 009 /** 010 * Represents an atmospheric phase interference weather constraint. 011 * @author slovelan 012 */ 013 014 @XmlRootElement 015 public class ConstraintApi extends Constraint { 016 017 private static final double UNSPECIFIED_PHASE = -1; 018 019 protected double phase = UNSPECIFIED_PHASE; 020 021 022 //------------------------------------------------------------------------- 023 // Construction 024 //------------------------------------------------------------------------- 025 026 public ConstraintApi( double amount ){ 027 constraintType = ConstraintType.API; 028 initialize( amount ); 029 } 030 031 public ConstraintApi(){ 032 constraintType = ConstraintType.API; 033 initialize( UNSPECIFIED_PHASE ); 034 } 035 036 /** 037 * Copy constructor in lieu of the troublesome clone. 038 */ 039 040 public ConstraintApi( ConstraintApi theCopy ){ 041 super( theCopy ); 042 initialize( (Double)theCopy.getValue()); 043 044 } 045 046 private final void initialize( double phase ){ 047 this.constraintType = ConstraintType.API; 048 if ( phase >= 0 ){ 049 this.phase = phase; 050 } 051 else { 052 this.phase = UNSPECIFIED_PHASE; 053 } 054 } 055 056 public String getDisplayName(){ 057 return "Atmospheric Phase Interference"; 058 } 059 060 public boolean isSpecified(){ 061 boolean specified = true; 062 if ( phase == UNSPECIFIED_PHASE ){ 063 specified = false; 064 } 065 return specified; 066 } 067 068 public void reset(){ 069 phase = UNSPECIFIED_PHASE; 070 } 071 072 //------------------------------------------------------------------------- 073 // API 074 //------------------------------------------------------------------------- 075 076 public double getPhase(){ 077 return phase; 078 } 079 080 public void setPhase( double phase ){ 081 initialize( phase ); 082 } 083 084 public Object getValue(){ 085 return new Double( phase ); 086 } 087 088 089 090 //-------------------------------------------------------------------------------- 091 // Probability 092 //-------------------------------------------------------------------------------- 093 094 095 public ConstraintProbability getProbabilitySuccess( List<Constraint> constraints ){ 096 097 ConstraintProbability result = new ConstraintProbability(); 098 result.setConstraintType( constraintType ); 099 result.setProbabilitySuccess( ConstraintProbability.SUCCESS ); 100 101 //We allow the other constraint if it is less than or equal 102 //to this one and reject it otherwise. 103 //TODO: Need to make this more sophisticated so it is not just a 0/1 measurement. 104 if ( isSpecified()){ 105 Constraint sbConstraint = getConstraint( constraints ); 106 if ( sbConstraint instanceof ConstraintApi ){ 107 ConstraintApi otherConstraint = (ConstraintApi) sbConstraint; 108 double otherPhase = (Double) otherConstraint.getValue(); 109 if ( this.phase > otherPhase ){ 110 result.setProbabilitySuccess( ConstraintProbability.FAILURE ); 111 result.setMessage( "The current api of "+phase+" is does not meet the api tolerance of "+otherPhase ); 112 } 113 } 114 else { 115 result.setMessage( ConstraintProbability.NO_CONSTRAINT_SB ); 116 } 117 } 118 119 return result; 120 } 121 122 123 }