1   /* Copyright 2002-2025 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 org.hipparchus.linear.MatrixUtils;
20  import org.hipparchus.linear.RealMatrix;
21  import org.junit.jupiter.api.Assertions;
22  import org.junit.jupiter.api.Test;
23  import org.orekit.gnss.PredefinedGnssSignal;
24  import org.orekit.utils.ParameterDriver;
25  
26  import java.util.ArrayList;
27  import java.util.List;
28  
29  public class AmbiguitySolverTest {
30  
31      @Test
32      public void testJoostenTiberiusFAQ() {
33          // this test corresponds to the "LAMBDA: FAQs" paper by Peter Joosten and Christian Tiberius
34  
35          final List<ParameterDriver> ambiguitiesDrivers = createAmbiguities(5.450, 3.100, 2.970);
36          final RealMatrix covariance = MatrixUtils.createRealMatrix(new double[][] {
37              { 6.290, 5.978, 0.544 },
38              { 5.978, 6.292, 2.340 },
39              { 0.544, 2.340, 6.288 }
40          });
41  
42          // acceptance ratio not met
43          Assertions.assertTrue(new AmbiguitySolver(ambiguitiesDrivers, new LambdaMethod(),
44                                                new SimpleRatioAmbiguityAcceptance(0.5)).
45                            fixIntegerAmbiguities(0, ambiguitiesDrivers, covariance).
46                            isEmpty());
47  
48          List<ParameterDriver> fixed = new AmbiguitySolver(ambiguitiesDrivers, new LambdaMethod(),
49                                                            new SimpleRatioAmbiguityAcceptance(0.8)).
50                                        fixIntegerAmbiguities(0, ambiguitiesDrivers, covariance);
51          Assertions.assertEquals(3, fixed.size());
52          Assertions.assertEquals(5, fixed.get(0).getValue(), 1.0e-15);
53          Assertions.assertEquals(3, fixed.get(1).getValue(), 1.0e-15);
54          Assertions.assertEquals(4, fixed.get(2).getValue(), 1.0e-15);
55      }
56  
57      private List<ParameterDriver> createAmbiguities(double...floatValues) {
58          final AmbiguityCache cache = new AmbiguityCache();
59          final List<ParameterDriver> ambiguitiesDrivers = new ArrayList<>(floatValues.length);
60          for (int i = 0; i < floatValues.length; ++i) {
61              final ParameterDriver driver = cache.getAmbiguity("emitter-" + i, "receiver",
62                                                                PredefinedGnssSignal.E01.getWavelength());
63              driver.setValue(floatValues[i]);
64              driver.setSelected(true);
65              ambiguitiesDrivers.add(driver);
66          }
67          return ambiguitiesDrivers;
68      }
69  
70  }
71