1   /* Copyright 2002-2022 CS GROUP
2    * Licensed to CS GROUP (CS) under one or more
3    * contributor license agreements.  See the NOTICE file distributed with
4    * this work for additional information regarding copyright ownership.
5    * CS licenses this file to You under the Apache License, Version 2.0
6    * (the "License"); you may not use this file except in compliance with
7    * the License.  You may obtain a copy of the License at
8    *
9    *   http://www.apache.org/licenses/LICENSE-2.0
10   *
11   * Unless required by applicable law or agreed to in writing, software
12   * distributed under the License is distributed on an "AS IS" BASIS,
13   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14   * See the License for the specific language governing permissions and
15   * limitations under the License.
16   */
17  package org.orekit.estimation.measurements.gnss;
18  
19  import java.util.ArrayList;
20  import java.util.List;
21  
22  import org.hipparchus.linear.MatrixUtils;
23  import org.hipparchus.linear.RealMatrix;
24  import org.junit.Assert;
25  import org.junit.Test;
26  import org.orekit.utils.ParameterDriver;
27  
28  public class AmbiguitySolverTest {
29  
30      @Test
31      public void testJoostenTiberiusFAQ() {
32          // this test corresponds to the "LAMBDA: FAQs" paper by Peter Joosten and Christian Tiberius
33  
34          final List<ParameterDriver> ambiguitiesDrivers = createAmbiguities(5.450, 3.100, 2.970);
35          final RealMatrix covariance = MatrixUtils.createRealMatrix(new double[][] {
36              { 6.290, 5.978, 0.544 },
37              { 5.978, 6.292, 2.340 },
38              { 0.544, 2.340, 6.288 }
39          });
40  
41          // acceptance ratio not met
42          Assert.assertTrue(new AmbiguitySolver(ambiguitiesDrivers, new LambdaMethod(),
43                                                new SimpleRatioAmbiguityAcceptance(0.5)).
44                            fixIntegerAmbiguities(0, ambiguitiesDrivers, covariance).
45                            isEmpty());
46  
47          List<ParameterDriver> fixed = new AmbiguitySolver(ambiguitiesDrivers, new LambdaMethod(),
48                                                            new SimpleRatioAmbiguityAcceptance(0.8)).
49                                        fixIntegerAmbiguities(0, ambiguitiesDrivers, covariance);
50          Assert.assertEquals(3, fixed.size());
51          Assert.assertEquals(5, fixed.get(0).getValue(), 1.0e-15);
52          Assert.assertEquals(3, fixed.get(1).getValue(), 1.0e-15);
53          Assert.assertEquals(4, fixed.get(2).getValue(), 1.0e-15);
54      }
55  
56      private List<ParameterDriver> createAmbiguities(double...floatValues) {
57          final List<ParameterDriver> ambiguitiesDrivers = new ArrayList<>(floatValues.length);
58          for (int i = 0; i < floatValues.length; ++i) {
59              final ParameterDriver driver = new ParameterDriver(Phase.AMBIGUITY_NAME + i, 0.0, 1.0,
60                                                                 Double.NEGATIVE_INFINITY,
61                                                                 Double.POSITIVE_INFINITY);
62              driver.setValue(floatValues[i]);
63              driver.setSelected(true);
64              ambiguitiesDrivers.add(driver);
65          }
66          return ambiguitiesDrivers;
67      }
68  
69  }
70