public void A1_CreateAndSaveModel() { String errorMessage = null; try { WeibullMarkovModel model = new WeibullMarkovModel(5, 3, true, null, false, 0.07); String[] keys = model.AllocateKeys(4, out errorMessage); Assert.IsNotNull(keys, errorMessage); Assert.IsTrue(keys.Length == 4, "keys.Length <> 4"); keys[0] = "раз"; keys[1] = "два"; keys[2] = "три"; keys[3] = "четыре"; WeibullMarkovConditionState state1 = model.AddConditionState(27.10497512, 3.012514254, 0, 0, 0, 0, out errorMessage); Assert.IsNotNull(state1, errorMessage); WeibullMarkovConditionState state2 = model.AddConditionState(31.32526401, 3.266009211, 0, 0, 0, 0, out errorMessage); Assert.IsNotNull(state2, errorMessage); WeibullMarkovConditionState state3 = model.AddConditionState(19.18160534, 5.764593918, 0, 0, 0, 0, out errorMessage); Assert.IsNotNull(state3, errorMessage); WeibullMarkovConditionState state4 = model.AddConditionState(10.81636701, 4.670420484, 0, 0, 0, 0, out errorMessage); Assert.IsNotNull(state4, errorMessage); Assert.IsTrue(model.States.Count == 4, "Wrong number of condition states"); WeibullMarkovAction action21 = state2.AddAction(1, 4, true, 1.92); action21.TranProb[0] = 0.99; action21.TranProb[1] = 0.01; WeibullMarkovAction action31 = state3.AddAction(1, 4, true, 23.04); action31.TranProb[0] = 0.9; action31.TranProb[1] = 0.05; action31.TranProb[2] = 0.03; action31.TranProb[3] = 0.02; WeibullMarkovAction action32 = state3.AddAction(2, 4, true, 190.04); action32.TranProb[0] = 1.00; WeibullMarkovAction action41 = state4.AddAction(1, 4, true, 232.28); action41.TranProb[0] = 0.7; action41.TranProb[1] = 0.2; action41.TranProb[2] = 0.05; action41.TranProb[3] = 0.05; WeibullMarkovAction action42 = state4.AddAction(2, 4, true, 600.0); action42.TranProb[0] = 1.00; Double F = model.States[0].ComputeTFF(); Assert.IsTrue(F == 0.99, "F<>0.99"); Boolean ok = model.SaveToXml(modelXmlFileName, out errorMessage); Assert.IsTrue(ok, errorMessage); if (ok && !String.IsNullOrEmpty(modelXsdFileName)) { ok = TWeibullMarkovLibrary.Utilities.ValidateXMLvsXSD(modelXmlFileName, modelXsdFileName, null, out errorMessage); Assert.IsTrue(ok, errorMessage); } } catch (Exception ex) { Assert.IsTrue(false, ex.Message); } }
public void EstimateModel(UCWeibullPane tp1, UCWeibullPane tp2, UCWeibullPane tp3, UCWeibullPane tp4, UCActionPane a1, UCActionPane a2, UCFailureCost failCost, UCDiscounting disc) { Boolean ok = true; try { String errorMessage = null; Double discRate = disc.AnnualRate; Boolean fcEstimate = failCost.Estimate; Boolean fcOverride = failCost.Override; Double? fcCost = failCost.FailureCost; UCWeibullPane[] tp = new UCWeibullPane[] { tp1, tp2, tp3, tp4 }; TWeibullMarkovLibrary.WeibullMarkovModel model = new WeibullMarkovModel(4, 3, fcEstimate, fcCost, fcOverride, discRate); // We are assuming throughout that the do nothing cost is zero TWeibullMarkovLibrary.WeibullMarkovConditionState[] state = new WeibullMarkovConditionState[4]; for (int i = 0; ok && i < 4; i++) { state[i] = model.AddConditionState(tp[i].Eta, tp[i].Beta, 0.0, tp[i].T, tp[i].f, tp[i].ff, out errorMessage); if (state[i] == null) { throw new Exception(errorMessage); } state[i].t50 = tp[i].t50; state[i].t9X = tp[i].t9x; state[i].x = tp[i].x; if (a1.IsApplicableToState(i)) { TWeibullMarkovLibrary.WeibullMarkovAction action = state[i].AddAction(1, 4, true, a1.GetCost(i)); for (Int32 j = 0; j < 4; j++) { action.TranProb[j] = a1.GetTranProb(i, j); } } if (a2.IsApplicableToState(i)) { TWeibullMarkovLibrary.WeibullMarkovAction action = state[i].AddAction(2, 4, true, a2.GetCost(i)); for (Int32 j = 0; j < 4; j++) { action.TranProb[j] = a2.GetTranProb(i, j); } } } if (ok) { String fileName = MapPath("~/App_Data/WeibullMarkovModel.xml"); ok = model.SaveToXml(fileName, out errorMessage); if (!ok) { throw new Exception(errorMessage); } String localSchemaPath = MapPath(SCHEMA_FILE_PATH); if (System.IO.File.Exists(localSchemaPath)) { ok = TWeibullMarkovLibrary.Utilities.ValidateXMLvsXSD(fileName, localSchemaPath, null, out errorMessage); if (!ok) { throw new Exception(errorMessage); } } } } catch (Exception ex) { labelError.Text = ex.Message; labelInfo.Text = String.Empty; labelError.Visible = true; labelInfo.Visible = false; } }