// ------------------------------------------------------------------------------------- // !!! PRIVATE METHODS !!! // ------------------------------------------------------------------------------------- /// <summary> /// Calculates sum of setpoint control errors /// </summary> /// <param name="mySensors">sensors object with all measurements</param> /// <param name="myPlant">plant object</param> /// <param name="myFitnessParams">fitness params</param> /// <param name="noisy">if true then noisy measurements are used</param> /// <returns></returns> private static double calc_setpoint_errors(sensors mySensors, plant myPlant, biooptim.fitness_params myFitnessParams, bool noisy) { double diff_setpoints = 0; // to be returned value: control setpoint error double[] sim_t = mySensors.getTimeStream(); double t = mySensors.getCurrentTime(); double sim_val, ref_val; // last simulated value and reference value at time t // if (sim_t.Length > 3) { foreach (biooptim.setpoint mySetpoint in myFitnessParams.mySetpoints) { if (mySetpoint.s_operator == "") // then compare measurement of one sensor { string sensor_id = mySetpoint.sensor_id + "_" + mySetpoint.location; // get reference values always not noisy ref_val = mySensors.getMeasurementDAt(String.Format("ref_{0}_{1}", sensor_id, mySetpoint.index), "", t, 0, false); sim_val = mySensors.getCurrentMeasurementDind(sensor_id, mySetpoint.index, noisy); } else // compare measurement of a group of sensors, energy of all chps, gas of all digesters, ... { string s_operator = mySetpoint.location + "_" + mySetpoint.s_operator; // get reference values always not noisy ref_val = mySensors.getMeasurementDAt( String.Format("ref_{0}_{1}", mySetpoint.sensor_id, mySetpoint.index), "", t, 0, false); sim_val = mySensors.getCurrentMeasurementDind(myPlant, mySetpoint.sensor_id, s_operator, mySetpoint.index, noisy); } diff_setpoints += mySetpoint.scalefac * Math.Pow(ref_val - sim_val, 2); } } return(diff_setpoints); }
/// <summary> /// Calc u prime for substrate feed of all substrates saved in sensors at the /// current time /// </summary> /// <param name="mySensors"></param> /// <param name="mySubstrates"></param> /// <returns>|| u'(t) ||_2^2, where u is the vector of substrate feeds</returns> private double calcudot(biogas.sensors mySensors, biogas.substrates mySubstrates) { double t2 = mySensors.getCurrentTime(); if (t2 < 0) // no recorded value yet in no sensor { return(0); } double t1 = mySensors.getPreviousTime(); double[] Q1, Q2; // TODO // wenn init substrate feed nicht gegeben ist, dann ist am anfang der simulation // Q2 = Q1 // aktuell berechne ich in MATLAb noch init_substrate feed und addiere das am ende // zu udot hinzu, sollte erstmal ok sein mySensors.getMeasurementsAt("Q", "Q", t1, mySubstrates, out Q1); mySensors.getMeasurementsAt("Q", "Q", t2, mySubstrates, out Q2); // double udot = 0; for (int isubstrate = 0; isubstrate < mySubstrates.getNumSubstrates(); isubstrate++) { double u1 = Q1[isubstrate]; double u2 = Q2[isubstrate]; double udot1 = calcudot(t1, t2, u1, u2); udot += udot1 * udot1; } return(udot); }