View Javadoc
1   package nl.tudelft.simulation.dsol.swing.gui.inputparameters;
2   
3   import java.util.ArrayList;
4   import java.util.List;
5   
6   import org.djunits.unit.LengthUnit;
7   import org.djunits.value.vdouble.scalar.Length;
8   
9   import nl.tudelft.simulation.dsol.model.inputparameters.InputParameterBoolean;
10  import nl.tudelft.simulation.dsol.model.inputparameters.InputParameterDistContinuousSelection;
11  import nl.tudelft.simulation.dsol.model.inputparameters.InputParameterDistDiscreteSelection;
12  import nl.tudelft.simulation.dsol.model.inputparameters.InputParameterDouble;
13  import nl.tudelft.simulation.dsol.model.inputparameters.InputParameterDoubleScalar;
14  import nl.tudelft.simulation.dsol.model.inputparameters.InputParameterException;
15  import nl.tudelft.simulation.dsol.model.inputparameters.InputParameterMap;
16  import nl.tudelft.simulation.dsol.model.inputparameters.InputParameterSelectionList;
17  import nl.tudelft.simulation.jstats.streams.MersenneTwister;
18  import nl.tudelft.simulation.jstats.streams.StreamInterface;
19  
20  /**
21   * Test.java. <br>
22   * <br>
23   * Copyright (c) 2003-2023 Delft University of Technology, Jaffalaan 5, 2628 BX Delft, the Netherlands. All rights reserved. See
24   * for project information <a href="https://www.simulation.tudelft.nl/" target="_blank">www.simulation.tudelft.nl</a>. The
25   * source code and binary code of this software is proprietary information of Delft University of Technology.
26   * @author <a href="https://www.tudelft.nl/averbraeck" target="_blank">Alexander Verbraeck</a>
27   */
28  public class Test
29  {
30  
31      /**
32       * @param args String[]; empty
33       * @throws InputParameterException on error
34       */
35      public static void main(final String[] args) throws InputParameterException
36      {
37          InputParameterMap ipMap = new InputParameterMap("model", "Model data", "Input variables for the model", 1.0);
38  
39          InputParameterMap seMap = new InputParameterMap("economic", "Socio-economic", "Socio-economic data", 1.0);
40          ipMap.add(seMap);
41          for (String tgsbf : new String[] {"Textile", "Garment", "Steel", "Brick", "Food"})
42          {
43              for (String pcei : new String[] {"Production", "Consumption", "Import", "Export"})
44              {
45                  InputParameterDouble paramDouble = new InputParameterDouble(tgsbf + pcei, tgsbf + " " + pcei,
46                          tgsbf + " " + pcei + " in tonnes per year", 100000.0, 0.0, 1.0E12, true, true, "%f", 1.0);
47                  seMap.add(paramDouble);
48              }
49          }
50  
51          InputParameterMap trMap = new InputParameterMap("transport", "Transport", "Transport data", 2.0);
52          ipMap.add(trMap);
53          for (String tgsbf : new String[] {"Textile", "Garment", "Steel", "Brick", "Food"})
54          {
55              for (String rrw : new String[] {"Road", "Rail", "Water"})
56              {
57                  InputParameterDouble paramDouble = new InputParameterDouble(tgsbf + rrw, tgsbf + " " + rrw,
58                          tgsbf + " " + rrw + " in tonnes per year", 100000.0, 0.0, 1.0E12, true, true, "%f", 1.0);
59                  trMap.add(paramDouble);
60              }
61          }
62  
63          InputParameterMap xxMap = new InputParameterMap("other", "Other", "Other parameters", 3.0);
64          ipMap.add(xxMap);
65          InputParameterBoolean paramBool1 =
66                  new InputParameterBoolean("boolean1", "Boolean value 1", "Boolean value 1 using tickbox false", false, 1.0);
67          xxMap.add(paramBool1);
68          InputParameterBoolean paramBool2 =
69                  new InputParameterBoolean("boolean2", "Boolean value 2", "Boolean value 2 using tickbox true", true, 2.0);
70          xxMap.add(paramBool2);
71          List<String> countries = new ArrayList<>();
72          countries.add("USA");
73          countries.add("Netherlands");
74          countries.add("Germany");
75          countries.add("France");
76          countries.add("Belgium");
77          InputParameterSelectionList<String> paramSelect = new InputParameterSelectionList<String>("country", "Country",
78                  "Country to select", countries, "Netherlands", 4.0);
79          xxMap.add(paramSelect);
80          StreamInterface stream = new MersenneTwister(1L);
81          InputParameterDistContinuousSelection ipdcs = new InputParameterDistContinuousSelection("distCont",
82                  "Continuous distribution", "Continuous distribution", stream, 5.0);
83          xxMap.add(ipdcs);
84          InputParameterDistDiscreteSelection ipdds = new InputParameterDistDiscreteSelection("distDiscrete",
85                  "Discrete distribution", "Discrete distribution", stream, 6.0);
86          xxMap.add(ipdds);
87          InputParameterDoubleScalar<LengthUnit, Length> length = new InputParameterDoubleScalar<>("length", "Length",
88                  "Length of the trip", new Length(20.0, LengthUnit.LIGHTYEAR), 0.0, Double.MAX_VALUE, true, false, "%d", 7.0);
89          xxMap.add(length);
90  
91          // InputParameterString is = new InputParameterString("runName", "Name of run", "Description of the run", "", 1.0);
92          // ipMap.add(is); // should give error when displayed in a tabbed environment
93  
94          // InputParameterMap inputParameterMap = ipMap;
95          // InputParameterDistContinuous ipDist = new InputParameterDistContinuous("arrDist", "Arrival distribution",
96          // "Arrival distribution, e.g. DistExponential(lambda)", stream, new DistExponential(stream, 1.0), 1.0);
97          // ipMap.add(ipDist);
98          //
99          // InputParameterMap ipMap = getInputParameterMap();
100         // InputParameterDistContinuous arrDist = (InputParameterDistContinuous) ipMap.get("arrDist");
101         // arrDist.setDistValue(new DistExponential(arrDist.getStream(), 2.17));
102 
103         new TabbedParameterDialog(ipMap);
104 
105         System.out.println(ipMap.printValues());
106         System.out.println(((InputParameterMap) ipMap.get("other")).get("length").toString());
107         @SuppressWarnings("unchecked")
108         InputParameterDoubleScalar<LengthUnit, Length> ipds =
109                 (InputParameterDoubleScalar<LengthUnit, Length>) ((InputParameterMap) ipMap.get("other")).get("length");
110         Length l1 = ipds.getCalculatedValue();
111         Length l2 = (Length) ipMap.get("other.length").getCalculatedValue();
112         System.out.println(l1);
113         System.out.println(l2);
114     }
115 
116 }