I am using Constrained Minimize() in JSL and would like to build both the Zielfunktion and the dynamisch festgelegte Nebenbedingung, based on which variables appear in the objective equation.
In einfachen Fällen kann ich alles fest codieren, zum Beispiel:
R_nom = 0.1;
L_nom = 0.5;
S_nom = 48.2;
B_nom = 0.05;
R_eq = 0.1;
L_eq = 0.5;
S_eq = 48.2;
B_eq = 0.05;
R_sd = :sd_R;
L_sd = :sd_L;
S_sd = :sd_S;
B_sd = :sd_B;
bias_const = 1.5;
R_bias = R_sd * bias_const;
L_bias = L_sd * bias_const;
S_bias = S_sd * bias_const;
B_bias = B_sd * bias_const;
minFun = Constrained Minimize(
(16.388 * Pi() * R_nom ^ 2 * L_nom - B_nom) * S_nom,
{R_nom( R_eq - R_Bias, R_eq + R_Bias ), L_nom( L_eq - L_Bias, L_eq + L_Bias ), S_nom( S_eq - S_Bias, S_eq + S_Bias ),
B_nom( B_eq - B_Bias, B_eq + B_Bias )},
<
<TOLERANCE></TOLERANCE>
<P>Die <STRONG data-start="1086" data-end="1118">Gleichung kann sich jedoch dynamisch ändern</STRONG> , z. B.:</P> <CODE class=" language-jsl">R_nom^2 * L_nom // instead of 16.388 * Pi() * R_nom ^ 2 * L_nom - B_nom) * S_nom
In that case, I only want constraints for R_nom and L_nom, not for B_nom or S_nom.
Was ich erreichen möchte
-
Define the objective function as an expression (Expr()).
-
Ermitteln Sie, welche Eingabevariablen in der Gleichung verwendet werden (ich habe dafür eine Funktion erstellt).
varsUsed = {"R_nom","L_nom"}; //when equation is R_nom^2 * L_nom
-
Die Einschränkungsliste wird automatisch nur für diese Variablen erstellt.
-
Pass the dynamically generated constraint list into Constrained Minimize().
Aktueller Ansatz
Ich speichere Parametermetadaten (Nominalvariable, Gleichgewichtswert, Bias) in einem assoziativen Array, z. B.:
paramInfo = Associative Array();
paramInfo["R_nom"] = {R_nom, R_eq, R_bias};
paramInfo["L_nom"] = {L_nom, L_eq, L_bias};
paramInfo["S_nom"] = {S_nom, S_eq, S_bias};
paramInfo["B_nom"] = {B_nom, B_eq, B_bias};
Wo ich feststecke
I am having trouble Dynamisches Konstruieren gültiger Nebenbedingungsausdrücke in JSL so that they are accepted by Constrained Minimize().
Sie benötigen höchstwahrscheinlich eine Ausdrucksauswertung, die auch Namensausdrücke enthält. Dies könnte Ihnen einige Anregungen geben.
Names Default To Here(1);
params = Associative Array();
params["R_nom"] = {R_nom, R_eq, R_bias};
params["L_nom"] = {L_nom, L_eq, L_bias};
params["S_nom"] = {S_nom, S_eq, S_bias};
params["B_nom"] = {B_nom, B_eq, B_bias};
vars = {"R_nom","L_nom"};
l = {};
For Each({var}, vars,
e = Substitute(Expr(nom(eq - bias, eq + bias)),
Expr(nom), Name Expr(params[var][1]),
Expr(eq), Name Expr(params[var][2]),
Expr(bias), Name Expr(params[var][3]),
);
Insert Into(l, Name Expr(e));
);
minFun = EvalExpr(
Constrained Minimize(
(16.388 * Pi() * R_nom ^ 2 * L_nom - B_nom) * S_nom,
Expr(l),
<
<TOLERANCE></TOLERANCE>