yanweiyuan3
2023-08-09 588bc7829387dfc761cc25f06f77d4c81818bd10
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
Quintiq file version 2.0
#parent: #root
StaticMethod Create (LibOpt_OptimizerRunController controller, String datasetname, Key datasetkey, 
  String optimizername, Key runkey, Number runnr, 
  DateTime requestedon, Number threadsrequested) as LibOpt_ControllerRun
{
  Description:
  [*
    Create a new `LibOpt_ControllerRun`. 
    This `LibOpt_ControllerRun` is implicitly linked to a `LibOpt_Run` through the `LibOpt_ControllerRun.DatasetKey` and `LibOpt_ControllerRun.RunNr` attributes.
  *]
  TextBody:
  [*
    // evr3 Apr-26-2022 (created)
    if( controller.ConcurrentRunsMax() <= 0 )
    {
      // Throw an error if ConcurrentRunsMax is equal to zero, as this implies that no runs can start. 
      // This error is handled in HandleExceptionRunController and it will create a snapshot to inform the user. 
      error( Translations::LibOpt_OptimizerRunController_MaxConcurrentRunsIsZero() );
    }
    
    if( threadsrequested > controller.CPUThreadsMax() )
    {
      // Throw an error if more threads are requested than there are availble. 
      // The run controller works first-in-first-out. By throwing the error, we ensure that all other runs don't have to wait because this run cannot be started. 
      // This error is handled in HandleExceptionRunController and it will create a snapshot to inform the user. 
      error( Translations::LibOpt_OptimizerRunController_ErrorRequestedThreads( threadsrequested, controller.CPUThreadsMax() ) );
    }
    
    // Remove old stopped runs before starting new ones.
    controller.DeleteStoppedOptimizerRuns();
    
    run := controller.ControllerRun( relnew,
                                     DatasetName := datasetname,
                                     DatasetKey := datasetkey,
                                     OptimizerName := optimizername,
                                     RunKey := runkey,
                                     RunNr := runnr,
                                     RequestedOn := requestedon,
                                     CPUThreadsRequested := threadsrequested
                                     );
    return run;
  *]
  InterfaceProperties { Accessibility: 'Module' }
}