Ejemplo n.º 1
0
 public SimpleSetup(StateSpace space) : this(ompl_geometricPINVOKE.new_SimpleSetup__SWIG_1(StateSpace.getCPtr(space)), true)
 {
     if (ompl_geometricPINVOKE.SWIGPendingException.Pending)
     {
         throw ompl_geometricPINVOKE.SWIGPendingException.Retrieve();
     }
 }
Ejemplo n.º 2
0
 public SpaceInformation(StateSpace space) : this(ompl_basePINVOKE.new_SpaceInformation(StateSpace.getCPtr(space)), true)
 {
     if (ompl_basePINVOKE.SWIGPendingException.Pending)
     {
         throw ompl_basePINVOKE.SWIGPendingException.Retrieve();
     }
 }
Ejemplo n.º 3
0
 public SubspaceStateSampler(StateSpace space, StateSpace subspace, double weight) : this(ompl_basePINVOKE.new_SubspaceStateSampler(StateSpace.getCPtr(space), StateSpace.getCPtr(subspace), weight), true)
 {
     if (ompl_basePINVOKE.SWIGPendingException.Pending)
     {
         throw ompl_basePINVOKE.SWIGPendingException.Retrieve();
     }
 }
 public RealVectorDeterministicStateSampler(StateSpace space, DeterministicSequence sequence_ptr) : this(ompl_basePINVOKE.new_RealVectorDeterministicStateSampler__SWIG_3(StateSpace.getCPtr(space), DeterministicSequence.getCPtr(sequence_ptr)), true)
 {
     if (ompl_basePINVOKE.SWIGPendingException.Pending)
     {
         throw ompl_basePINVOKE.SWIGPendingException.Retrieve();
     }
 }
Ejemplo n.º 5
0
 public SO2DeterministicStateSampler(StateSpace space) : this(ompl_basePINVOKE.new_SO2DeterministicStateSampler__SWIG_1(StateSpace.getCPtr(space)), true)
 {
     if (ompl_basePINVOKE.SWIGPendingException.Pending)
     {
         throw ompl_basePINVOKE.SWIGPendingException.Retrieve();
     }
 }
 public RealVectorDeterministicStateSampler(StateSpace space, DeterministicStateSampler.DeterministicSamplerType type) : this(ompl_basePINVOKE.new_RealVectorDeterministicStateSampler__SWIG_0(StateSpace.getCPtr(space), (int)type), true)
 {
     if (ompl_basePINVOKE.SWIGPendingException.Pending)
     {
         throw ompl_basePINVOKE.SWIGPendingException.Retrieve();
     }
 }
Ejemplo n.º 7
0
 public ScopedStateStateSpace(StateSpace space, State state) : this(ompl_basePINVOKE.new_ScopedStateStateSpace__SWIG_3(StateSpace.getCPtr(space), State.getCPtr(state)), true)
 {
     if (ompl_basePINVOKE.SWIGPendingException.Pending)
     {
         throw ompl_basePINVOKE.SWIGPendingException.Retrieve();
     }
 }
 public SE2DeterministicStateSampler(StateSpace space, DeterministicSequence sequence_ptr, bool stretch_rv) : this(ompl_basePINVOKE.new_SE2DeterministicStateSampler__SWIG_3(StateSpace.getCPtr(space), DeterministicSequence.getCPtr(sequence_ptr), stretch_rv), true)
 {
     if (ompl_basePINVOKE.SWIGPendingException.Pending)
     {
         throw ompl_basePINVOKE.SWIGPendingException.Retrieve();
     }
 }
 public CompoundStateSampler(StateSpace space) : this(ompl_basePINVOKE.new_CompoundStateSampler(StateSpace.getCPtr(space)), true)
 {
     if (ompl_basePINVOKE.SWIGPendingException.Pending)
     {
         throw ompl_basePINVOKE.SWIGPendingException.Retrieve();
     }
 }
Ejemplo n.º 10
0
 public void getCommonSubspaces(StateSpace other, SWIGTYPE_p_std__vectorT_std__string_t subspaces)
 {
     ompl_basePINVOKE.StateSpace_getCommonSubspaces__SWIG_0(swigCPtr, StateSpace.getCPtr(other), SWIGTYPE_p_std__vectorT_std__string_t.getCPtr(subspaces));
     if (ompl_basePINVOKE.SWIGPendingException.Pending)
     {
         throw ompl_basePINVOKE.SWIGPendingException.Retrieve();
     }
 }
Ejemplo n.º 11
0
 public static void setDeterministicStateSamplerAllocator(StateSpace space, uint dim)
 {
     ompl_basePINVOKE.Determinism_setDeterministicStateSamplerAllocator(StateSpace.getCPtr(space), dim);
     if (ompl_basePINVOKE.SWIGPendingException.Pending)
     {
         throw ompl_basePINVOKE.SWIGPendingException.Retrieve();
     }
 }
Ejemplo n.º 12
0
        public void SetInvalid_RemovesValidState9()
        {
            var sp = new StateSpace();

            sp.SetInvalid(9);

            Assert.IsTrue(sp.GetValidStates().SequenceEqual(new int[] { 1, 2, 3, 4, 5, 6, 7, 8 }));
        }
Ejemplo n.º 13
0
 public void addSubspace(StateSpace component, double weight)
 {
     ompl_basePINVOKE.CompoundStateSpace_addSubspace(swigCPtr, StateSpace.getCPtr(component), weight);
     if (ompl_basePINVOKE.SWIGPendingException.Pending)
     {
         throw ompl_basePINVOKE.SWIGPendingException.Retrieve();
     }
 }
Ejemplo n.º 14
0
        double P()
        {
            if (fb == null || fb.Count == 0)
            {
                throw new Exception("You have to call DoWork() first");
            }

            return(StateSpace.Sum(state => fb[state][T - 1]));
        }
Ejemplo n.º 15
0
        public static AdvancedStateCopyOperation copyStateData(StateSpace destS, State dest, StateSpace sourceS, State source, SWIGTYPE_p_std__vectorT_std__string_t subspaces)
        {
            AdvancedStateCopyOperation ret = (AdvancedStateCopyOperation)ompl_basePINVOKE.copyStateData__SWIG_2(StateSpace.getCPtr(destS), State.getCPtr(dest), StateSpace.getCPtr(sourceS), State.getCPtr(source), SWIGTYPE_p_std__vectorT_std__string_t.getCPtr(subspaces));

            if (ompl_basePINVOKE.SWIGPendingException.Pending)
            {
                throw ompl_basePINVOKE.SWIGPendingException.Retrieve();
            }
            return(ret);
        }
Ejemplo n.º 16
0
        public static AdvancedStateCopyOperation copyStateData(StateSpace destS, State dest, StateSpace sourceS, State source)
        {
            AdvancedStateCopyOperation ret = (AdvancedStateCopyOperation)ompl_basePINVOKE.copyStateData__SWIG_0(StateSpace.getCPtr(destS), State.getCPtr(dest), StateSpace.getCPtr(sourceS), State.getCPtr(source));

            if (ompl_basePINVOKE.SWIGPendingException.Pending)
            {
                throw ompl_basePINVOKE.SWIGPendingException.Retrieve();
            }
            return(ret);
        }
Ejemplo n.º 17
0
        public bool covers(StateSpace other)
        {
            bool ret = ompl_basePINVOKE.StateSpace_covers__SWIG_0(swigCPtr, StateSpace.getCPtr(other));

            if (ompl_basePINVOKE.SWIGPendingException.Pending)
            {
                throw ompl_basePINVOKE.SWIGPendingException.Retrieve();
            }
            return(ret);
        }
Ejemplo n.º 18
0
        public StateSampler allocSubspaceStateSampler(StateSpace subspace)
        {
            global::System.IntPtr cPtr = ompl_basePINVOKE.StateSpace_allocSubspaceStateSampler__SWIG_0(swigCPtr, StateSpace.getCPtr(subspace));
            StateSampler          ret  = (cPtr == global::System.IntPtr.Zero) ? null : new StateSampler(cPtr, true);

            if (ompl_basePINVOKE.SWIGPendingException.Pending)
            {
                throw ompl_basePINVOKE.SWIGPendingException.Retrieve();
            }
            return(ret);
        }
Ejemplo n.º 19
0
        public StateSpace getSubspace(string name)
        {
            global::System.IntPtr cPtr = ompl_basePINVOKE.CompoundStateSpace_getSubspace__SWIG_1(swigCPtr, name);
            StateSpace            ret  = (cPtr == global::System.IntPtr.Zero) ? null : new StateSpace(cPtr, true);

            if (ompl_basePINVOKE.SWIGPendingException.Pending)
            {
                throw ompl_basePINVOKE.SWIGPendingException.Retrieve();
            }
            return(ret);
        }
Ejemplo n.º 20
0
        public static StateSampler allocHalton(StateSpace space, uint dim)
        {
            global::System.IntPtr cPtr = ompl_basePINVOKE.Determinism_allocHalton(StateSpace.getCPtr(space), dim);
            StateSampler          ret  = (cPtr == global::System.IntPtr.Zero) ? null : new StateSampler(cPtr, true);

            if (ompl_basePINVOKE.SWIGPendingException.Pending)
            {
                throw ompl_basePINVOKE.SWIGPendingException.Retrieve();
            }
            return(ret);
        }
Ejemplo n.º 21
0
        public StateSpace getStateSpace()
        {
            global::System.IntPtr cPtr = ompl_geometricPINVOKE.SimpleSetup_getStateSpace(swigCPtr);
            StateSpace            ret  = (cPtr == global::System.IntPtr.Zero) ? null : new StateSpace(cPtr, true);

            if (ompl_geometricPINVOKE.SWIGPendingException.Pending)
            {
                throw ompl_geometricPINVOKE.SWIGPendingException.Retrieve();
            }
            return(ret);
        }
Ejemplo n.º 22
0
        public override double P()
        {
            if (fb == null || fb.Count == 0)
            {
                throw new Exception("You have to call DoWork() first");
            }

            return
                (StateSpace.Sum(
                     state =>
                     InitialProbabilitiesOfStates[state] * EmissionMatrix[state, SequenceOfObservations[0]] *
                     fb[state][0]));
        }
Ejemplo n.º 23
0
        public static State MinusOneUnit(this StateSpace ss, IMDPState s, Route route)
        {
            IMDPState _s = s.Clone();

            foreach (Product p in route)
            {
                foreach (Resource r in p)
                {
                    if ((_s as State).Keys.Contains(r) && (_s as State)[r] > 0)
                    {
                        (_s as State)[r] -= 1;
                    }
                }
            }
            return(ss.FirstOrDefault(i => i.Equals(_s)) as State);
        }
Ejemplo n.º 24
0
        private void ValidateParameters()
        {
            if (EmissionMatrix == null || TransitionMatrix == null || SequenceOfObservations == null ||
                StateSpace == null || ObservationSpace == null)
            {
                throw new ArgumentException("Parameters cannot be null");
            }

            if (ObservationSpace.Length != EmissionMatrix.GetLength(1) || ObservationSpace.Length == 0)
            {
                throw new ArgumentException("N should be greater than 0 and consistent");
            }

#if _USE_ARRAYS_INSTEAD_OF_MATRIX_HASHTABLE
            if (StateSpace.Length != TransitionMatrix.GetLength(0) || TransitionMatrix.GetLength(0) != TransitionMatrix.GetLength(1) || TransitionMatrix.GetLength(1) != EmissionMatrix.GetLength(0) || EmissionMatrix.GetLength(0) != InitialProbabilitiesOfStates.Length || StateSpace.Length == 0)
            {
                throw new ArgumentException("K should be greater than 0 and consistent");
            }
#else
            if (StateSpace.Length != TransitionMatrix.GetLength(0) ||
                TransitionMatrix.GetLength(0) != TransitionMatrix.GetLength(1) ||
                TransitionMatrix.GetLength(1) != EmissionMatrix.GetLength(0) ||
                EmissionMatrix.GetLength(0) != InitialProbabilitiesOfStates.Count || StateSpace.Length == 0)
            {
                throw new ArgumentException("K should be greater than 0 and consistent");
            }
#endif
            if (SequenceOfObservations.Length == 0)
            {
                throw new ArgumentException("T should be greater than 0 and consistent");
            }

            if (
                StateSpace.Select(state => ObservationSpace.Sum(observation => EmissionMatrix[state, observation]))
                .Any(sum => sum <= 0.99 || sum >= 1.01))
            {
                throw new ArgumentException("EmissionMatrix has not normalized probabilities"); //Exception("Emi");
            }

            if (
                StateSpace.Select(state1 => StateSpace.Sum(state2 => TransitionMatrix[state1, state2]))
                .Any(sum => sum <= 0.99 || sum >= 1.01))
            {
                throw new ArgumentException("TransitionMatrix has not normalized probabilities"); //Exception("Emi");
            }
        }
        public override void DoWork()
        {
            base.DoWork();

            AlphaPass();
            BetaPass();

            _probabilitySuffix = StateSpace.Sum(
                state =>
                InitialProbabilitiesOfStates[state] * EmissionMatrix[state, SequenceOfObservations[0]] *
                beta[state][0]);
            _probabilityPrefix = StateSpace.Sum(state => alpha[state][T - 1]);

            var TOLERANCE = 1e-3;

            if (Math.Abs((_probabilitySuffix - _probabilityPrefix) / _probabilityPrefix) > TOLERANCE)
            {
                throw new Exception("Probabilities are not equal");
            }

            // Probability = (_probabilitySuffix + _probabilityPrefix)/2.0;

            LogProbability = 0.0;


            for (int i = 0; i < T; i++)
            {
                LogProbability -= Math.Log(c[i]);
            }
            Probability = Math.Exp(LogProbability);

            Output = new TState[T];

            for (var i = 0; i < T; i++)
            {
                var mostProbableState = StateSpace.Aggregate(
                    (s1, s2) =>
                    alpha[s1][i] * beta[s1][i] >
                    alpha[s2][i] * beta[s2][i]
                            ? s1
                            : s2);
                Output[i] = mostProbableState;
            }
        }
Ejemplo n.º 26
0
        /// <summary>
        /// Populate states reachable from initial state within the current number of iterations
        /// </summary>
        private void ExtendStateSpace(IDeterministicPolicy <TState> policy)
        {
            var previousLayer = StateSpace[_iteration - 1];

            if (StateSpace.ContainsKey(_iteration))
            {
                return;
            }
            var layer = new HashSet <TState>();

            if (_iteration > 2)
            {
                layer = StateSpace[_iteration - 2];
                layer.Clear();
            }

            var distinctLayer = new List <TState>();
            var nextStates    = new HashSet <TState>();

            foreach (var state in previousLayer)
            {
                var action = policy[state];
                if (action == null)
                {
                    continue;
                }

                nextStates.UnionWith(action[state]);
            }

            foreach (var nextState in nextStates)
            {
                if (AllStateSpace.Add(nextState))
                {
                    distinctLayer.Add(nextState);
                }

                layer.Add(nextState);
            }

            StateSpace[_iteration]         = layer;
            DistinctStateSpace[_iteration] = distinctLayer;
        }
Ejemplo n.º 27
0
 public override void DoWork()
 {
     base.DoWork();
     foreach (var state in StateSpace)
     {
         fb[state][T - 1] = 1;
         //InitialProbabilitiesOfStates[state] * EmissionMatrix[state, SequenceOfObservations[T - 1]];
     }
     for (var i = T - 2; i >= 0; i--)
     {
         foreach (var kState in StateSpace)
         {
             fb[kState][i] =
                 StateSpace.Sum(
                     lState =>
                     TransitionMatrix[kState, lState] * EmissionMatrix[lState, SequenceOfObservations[i + 1]] *
                     fb[lState][i + 1]);
         }
     }
 }
Ejemplo n.º 28
0
        public IMDPStateSpace GenStateSpace(IMDPState s, IMDPDecision a)
        {
            //目前状态减去开放产品集中的产品
            IMDPStateSpace subss = new StateSpace();

            if ((s as State).CanSupportDecision(a as Decision))
            {
                foreach (Product p in (a as Decision).OpenProductSet)
                {
                    IMDPState _s = (_ss as StateSpace).MinusOneUnit(s, p);
                    if (!subss.Contains(_s))
                    {
                        subss.Add(_s);
                    }
                }
                //再加入本身
                subss.Add(s);
            }

            return(subss);
        }
 public CasinoState(StateSpace stateSpace, int result)
 {
     StateSpace = stateSpace;
     Result     = result;
 }
Ejemplo n.º 30
0
 internal static global::System.Runtime.InteropServices.HandleRef getCPtr(StateSpace obj)
 {
     return((obj == null) ? new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero) : obj.swigCPtr);
 }