close Warning: Can't synchronize with repository "(default)" (/var/svn/mms does not appear to be a Subversion repository.). Look in the Trac log for more information.

Ticket #894: checks_functions.tol

File checks_functions.tol, 9.9 KB (added by CN=Alvaro Garcia Camacho, 13 years ago)
Line 
1//////////////////////////////////////////////////////////////////////////////
2Set FindProb(MMS::@Model mod)
3//////////////////////////////////////////////////////////////////////////////
4{
5  MMS::@DataSet oo = mod::GetDataSet(?);
6  Set variables = oo::GetVariables(?);
7  //Separo las i de las d según si tienen dependencias o no.
8  Set variables.i =  Select(variables,
9                  Real(MMS::@Variable var){var::HasDependences(?)==0});
10  //Set de variables problemáticas.
11  Set problem = Select(variables.i, Real (MMS::@Variable v) { //MMS::@Variable v = variables.i[614]
12    WriteLn("Vamos por "+v::_.name +", "+ FormatReal(v::GetIndex(?))
13            +" de "+ FormatReal(Card(variables.i)));
14    Real preShow = Show(False, "ALL");
15    Real nError = Copy(NError);
16    Anything v::GetData(?);
17    //Text exrp = v::GetExpression(?);
18    //Eval(exrp);
19    Real Show(preShow, "ALL");
20    nError!=NError
21  });
22  Set problem_nom.i = EvalSet(problem,Text(MMS::@Variable v) {Name(v)})
23};
24//////////////////////////////////////////////////////////////////////////////
25PutDescription("Devuelve un set con los nombres de las variables
26 independientes que provocan errores.",FindProb);
27//////////////////////////////////////////////////////////////////////////////
28
29Set OffByName(Set problem_nom.i,MMS::@Model mod)
30{
31  //Submodelos.
32  Set subm = mod::GetSubmodels(?);
33  Set off_prob1 = EvalSet(subm, Set(MMS::@Submodel sub) //MMS::@Submodel sub=subm[3]
34  {
35    Set expli = sub::GetExpTerms(?);
36    Set des = EvalSet(expli, Real(MMS::@ExpTermOmega exp) //MMS::@ExpTermOmega exp = expli[55]
37    {
38      Text nn = exp::GetName(?);
39      MMS::@Variable va = exp::GetInput(?);
40      MMS::@Variable vaa = va::GetVariable(?);
41      Set depe = If(vaa::HasDependences(?)!=0,vaa::GetDependences(?),[[vaa]]);
42      Set oor = EvalSet( depe, Real(MMS::@MVariable vari)
43      {
44        Set depe2 = If(vari::HasDependences(?)!=0,vari::GetDependences(?),[[vari]]);
45        Set oor2 =  EvalSet( depe2, Real(MMS::@MVariable vari2)
46        {
47          Text nok = Name(vari2);
48          Set versi = Select(problem_nom.i,Real(Text pr)
49          {
50           pr==nok
51          });
52          Card(versi)
53        });
54        Real condi2 = SetSum(oor2)
55      });
56      Real condi = SetSum(oor);
57      Eval("Real " +nn + "_off = If (condi>0,exp::SetIsActive(0),0)")
58    });
59    Eval ("Set _" + sub::GetName(?) + " = des")
60  });
61
62  Set off_prob2=Copy(Empty);
63  EvalSet( off_prob1, Set(Set cc)//Set cc = off_prob[3]
64  {
65   Text nomsub=Name(cc);
66   Set oo = Select(cc,Real(Real uu) {uu});
67   Set ii = EvalSet(oo,Text(Real uu){Name(uu)+"_"+nomsub});
68   Append(off_prob2,ii)
69  });
70  Set off_prob =  off_prob2
71};
72//////////////////////////////////////////////////////////////////////////////
73PutDescription("Desactiva los parámetros que usen variables cuyos nombres
74 coincidan con los elementos del set dado. Devuelve un set con los nombres de
75los inputs desactivados con la forma input + _prob_ + output.",OffByName);
76//////////////////////////////////////////////////////////////////////////////
77
78//////////////////////////////////////////////////////////////////////////////
79Set OffMiss(MMS::@Model mod)
80//////////////////////////////////////////////////////////////////////////////
81{
82  Set subm = mod::GetSubmodels(?);
83  Set off_miss1 = EvalSet(subm, Set(MMS::@Submodel sub) //MMS::@Submodel sub=subm[3]
84  {
85    Set expli = sub::GetExpTerms(?);
86    Set des = EvalSet(expli, Real(MMS::@ExpTermOmega exp) //MMS::@ExpTermOmega exp = expli[14]
87    {
88    If(exp::IsActive(?),
89      {
90        Text nn = exp::GetName(?);
91        MMS::@Variable va = exp::GetInput(?);
92        MMS::@Variable vaa = va::GetVariable(?);
93        Serie ser = vaa::GetData(?);
94        Real mis = HasUnknown(ser);
95        Eval("Real "+ nn + "_miss = If(mis,exp::SetIsActive(0),0)")
96      }
97      , 0
98      )
99    });
100    Eval("Set _" + sub::GetName(?) + " = des")
101  });
102  Set off_miss2=Copy(Empty);
103  EvalSet( off_miss1, Set(Set cc)//Set cc = off_prob[3]
104  {
105   Text nomsub=Name(cc);
106   Set oo = Select(cc,Real(Real uu) {uu});
107   Set ii = EvalSet(oo,Text(Real uu){Name(uu)+"_"+nomsub});
108   Append(off_miss2,ii)
109  });
110  Set off_miss =  off_miss2
111};
112//////////////////////////////////////////////////////////////////////////////
113PutDescription("Desactiva los parámetros cuyos inputs contienen omitidos.
114 Devuelve un set con los nombres de los inputs desactivados con la forma
115 input + _miss_ + output.",OffMiss);
116//////////////////////////////////////////////////////////////////////////////
117
118//////////////////////////////////////////////////////////////////////////////
119Set OffFlat(MMS::@Model mod)
120//////////////////////////////////////////////////////////////////////////////
121{
122  Set subm = mod::GetSubmodels(?);
123  Set off_flat1 = EvalSet(subm, Set(MMS::@Submodel sub) //MMS::@Submodel sub=subm[1]
124  {
125    Set expli = sub::GetExpTerms(?);
126    Set des = EvalSet(expli, Real(MMS::@ExpTermOmega exp) //MMS::@ExpTermOmega exp = expli[34]
127    {
128    If(exp::IsActive(?),
129      {
130        Text nn = exp::GetName(?);
131        MMS::@Variable va = exp::GetInput(?);
132        MMS::@Variable vaa = va::GetVariable(?);
133        Serie ser = vaa::GetData(?);
134        Real max = MaxS(ser);
135        Real min = MinS(ser);
136        Eval("Real " + nn + "_flat = If(max==min,exp::SetIsActive(0),0)")
137      }
138      , 0
139      )
140    });
141    Eval("Set _" + sub::GetName(?) + " = des")
142  });
143
144  Set off_flat2=Copy(Empty);
145  EvalSet( off_flat1, Set(Set cc)//Set cc = off_prob[3]
146  {
147   Text nomsub=Name(cc);
148   Set oo = Select(cc,Real(Real uu) {uu});
149   Set ii = EvalSet(oo,Text(Real uu){Name(uu)+"_"+nomsub});
150   Append(off_flat2,ii)
151  });
152  Set off_flat =  off_flat2
153};
154//////////////////////////////////////////////////////////////////////////////
155PutDescription("Desactiva los parámetros cuyos inputs son series planas.
156Devuelve un set con los nombres de los inputs desactivados con la forma
157 input + _miss_ + output.",OffFlat);
158//////////////////////////////////////////////////////////////////////////////
159
160//////////////////////////////////////////////////////////////////////////////
161Set OffBeginEnd(MMS::@Model mod, Date prin, Date final)
162//////////////////////////////////////////////////////////////////////////////
163{
164  Set subm = mod::GetSubmodels(?);
165  Set desenchufo_limits = EvalSet(subm, Set(MMS::@Submodel sub) //MMS::@Submodel sub=subm[3]
166  {
167    Set expli = sub::GetExpTerms(?);
168    Set des = EvalSet(expli, Real(MMS::@ExpTermOmega ex) //MMS::@ExpTermOmega ex = expli[48]
169    {
170    If(ex::IsActive(?),
171      {
172        Text nn = ex::GetName(?);
173        MMS::@Variable val = ex::GetInput(?);
174        MMS::@Variable vaal = val::GetVariable(?);
175        Serie ser = vaal::GetData(?);
176        Date ini = First(ser);
177        Date fin = Last(ser);
178        Real si_ini = ini > prin;
179        Real si_fin = fin < final;
180        Eval("Real " + nn + "_lim = If(si_ini + si_fin >0,
181                                       ex::SetIsActive(0),0)")
182      }
183      , 0
184      )
185    });
186    Eval("Set _"+ sub::GetName(?)+" = des")
187  });
188
189  Set off_lim2=Copy(Empty);
190  EvalSet( desenchufo_limits, Set(Set cc)//Set cc = off_prob[3]
191  {
192   Text nomsub=Name(cc);
193   Set oo = Select(cc,Real(Real uu) {uu});
194   Set ii = EvalSet(oo,Text(Real uu){Name(uu)+"_"+nomsub});
195   Append(off_lim2,ii)
196  });
197  Set off_lim =  off_lim2
198};
199//////////////////////////////////////////////////////////////////////////////
200PutDescription("Desactiva los parámetros cuyos inputs empiezan demasiado tarde
201 o acaban demasiado pronto. Devuelve un set con los nombres de los inputs
202 desactivados con la forma input + _lim_ + output.",OffBeginEnd);
203//////////////////////////////////////////////////////////////////////////////
204
205
206Set SelectDepend(Set problem,MMS::@Model mod)
207// Si sólo se ejecuta OffByName no se puede guardar la estimación luego.
208{
209  Set vam = EvalSet(problem, Set(Text nom)
210  {
211    Set varis = mod::GetDataSet(?)::GetVariables(?);
212    Set rom = EvalSet(varis, Set(MMS::@Variable var)
213    {
214      Set depe1 = If(var::HasDependences(?)!=0,var::GetDependences(?),[[var]]);
215      Set uuff1 = EvalSet(depe1,Set(MMS::@Variable var1)
216      {
217        Set depe2 =  If(var1::HasDependences(?)!=0,var1::GetDependences(?),[[var1]]);
218        Set uuff2 = EvalSet(depe2, Text (MMS::@Variable vari2)
219        {
220          Text quit = If(vari2::GetName(?)==nom , vari2::GetName(?),"")
221        });
222        Set quit2 = Select(uuff2, Real(Text oo) {oo!=""});
223        Set Eval("Set "+ var1::GetName(?)+"_n= quit2")
224      });
225      Set Eval("Set "+var::GetName(?)+" = uuff1")
226    });
227    Set jor = EvalSet(rom,Real(Set xx)
228    {
229      Set cardis = EvalSet(xx, Real(Set yy) {Card(yy)});
230      Real Eval("Real "+Name(xx)+" = SetSum(cardis)")
231    });
232    Set Select(jor,Real(Real uu) {uu>0})
233  });
234  Set mm = BinGroup("<<",vam);
235  Set nn = EvalSet(mm, Text(Real oo) {Name(oo)})
236};
237//////////////////////////////////////////////////////////////////////////////
238PutDescription("Selecciona las variables cuyos nombres, o los de sus
239 dependencias, o los de las dependencias de sus dependencias, coincidan con
240 los elementos del set dado. Devuelve un set con los nombres de las variables
241encontradas.",SelectDepend);
242//////////////////////////////////////////////////////////////////////////////
243
244Set RemoveByName(Set borrar,MMS::@Model mod)
245{
246  Set vam = EvalSet(borrar, Text(Text nom)
247  {
248    Set varis = mod::GetDataSet(?)::GetVariables(?);
249    Set cc = EvalSet(varis,Real(MMS::@Variable var)
250      {
251        Text name = var::GetName(?);
252        Real If(name==nom, var::Delete(?),0)
253      });
254    nom
255  })
256};
257//////////////////////////////////////////////////////////////////////////////
258PutDescription("Elimina las variables cuyos nombres coincidan con los
259 elementos del set dado. Devuelve un set con los nombres de las variables
260eliminadas.",RemoveByName);
261//////////////////////////////////////////////////////////////////////////////