private void CreateSampleSizeTable() { Storage.Storage storage = Job.Optimizer.Storage; storage.Query("DROP TABLE IF EXISTS `gcpso_samplesize`"); storage.Query("CREATE TABLE `gcpso_samplesize` (`id` INTEGER PRIMARY KEY, `iteration` INT, `successes` INT, `failures` INT, `sample_size` DOUBLE)"); }
public override void FromStorage(Storage.Storage storage, Storage.Records.Optimizer optimizer) { base.FromStorage(storage, optimizer); uint priority = 0; storage.Query("SELECT `expression`, `condition` FROM `stages` ORDER BY `id`", delegate(IDataReader reader) { string expression = Storage.Storage.As <string>(reader[0]); string condition = Storage.Storage.As <string>(reader[1]); d_stages.Add(new Stage(expression, condition, priority++)); return(true); }); foreach (Solution sol in Job.Optimizer.Population) { UpdateFitnessStage(sol); PSO.Particle p = (PSO.Particle)sol; UpdateFitnessStage(p.PersonalBest); } UpdateFitnessStage(Job.Optimizer.Best); Setup(); }
private void StoreStages() { Storage.Storage storage = Job.Optimizer.Storage; storage.Query("DROP TABLE IF EXISTS `stages`"); storage.Query("CREATE TABLE `stages` (`id` INTEGER PRIMARY KEY, `condition` TEXT, `expression` TEXT)"); for (int i = 0; i < d_stages.Count; ++i) { Stage stage = d_stages[i]; storage.Query("INSERT INTO `stages` (`condition`, `expression`) VALUES (@0, @1)", stage.Condition != null ? stage.Condition.Text : null, stage.Expression.Text); } }
public override void FromStorage(Storage.Storage storage, Storage.Records.Optimizer optimizer) { base.FromStorage(storage, optimizer); storage.Query("SELECT `id` FROM `constraints` ORDER BY `id`", delegate(IDataReader reader) { ConstraintMatrix cons = new ConstraintMatrix(Job.Optimizer.Configuration.PopulationSize); int consid = reader.GetInt32(0); storage.Query("SELECT `parameter` FROM `constraint_parameters` WHERE `constraint` = @0", delegate(IDataReader rd) { string name = reader.GetString(0); cons.Add(Job.Optimizer.Parameter(name)); d_constraintsFor[name] = cons; return(true); }, consid); storage.Query("SELECT `id`, `equality`, `value` FROM `constraint_equations` WHERE `constraint` = @0 ORDER BY `id`", delegate(IDataReader eqreader) { int eqid = eqreader.GetInt32(0); bool equality = eqreader.GetInt32(1) == 1; double val = eqreader.GetDouble(2); Linear.Vector coefficients = new Linear.Vector(); storage.Query("SELECT `value` FROM `constraint_coefficients` WHERE `equation` = @0 ORDER BY `id`", delegate(IDataReader cfreader) { coefficients.Add(cfreader.GetDouble(0)); return(true); }, eqid); cons.Add(new Linear.Constraint(equality, coefficients, val)); return(true); }, consid); d_constraints.Add(cons); return(true); }); }
public override void FromStorage(Storage.Storage storage, Storage.Records.Optimizer optimizer) { base.FromStorage(storage, optimizer); d_ranges.Clear(); d_numberOfSolutions = 0; // Read ranges from the storage storage.Query("SELECT `parameters`.`name`, `ranges`.`step_repr`, `ranges`.`steps_repr` FROM `ranges` LEFT JOIN `parameters` ON (`parameters`.`id` = `ranges`.`id`) ORDER BY `parameters`.`id`", delegate(IDataReader reader) { string name = (string)reader["name"]; string step = (string)reader["step_repr"]; string steps = (string)reader["steps_repr"]; Parameter parameter = Parameter(name); Range range = new Range(parameter.Name, parameter.Boundary); range.Step.Representation = step; if (!String.IsNullOrEmpty(steps)) { range.Steps = new NumericSetting(); range.Steps.Representation = steps; } d_ranges.Add(range); double[] all = range.ToArray(); if (d_numberOfSolutions == 0) { d_numberOfSolutions = (uint)all.Length; } else { d_numberOfSolutions *= (uint)all.Length; } return(true); }); object val = Storage.QueryValue("SELECT MAX(`index`) FROM `solution`"); if (val != null) { d_currentId = (uint)((Int64)val + 1); } else { d_currentId = 0; } }
private void StoreConstraints() { Storage.Storage storage = Job.Optimizer.Storage; storage.Query("DROP TABLE IF EXISTS `constraints`"); storage.Query("DROP TABLE IF EXISTS `constraint_parameters`"); storage.Query("DROP TABLE IF EXISTS `constraint_equations`"); storage.Query("DROP TABLE IF EXISTS `constraint_coefficients`"); storage.Query("CREATE TABLE `constraints` (`id` INTEGER PRIMARY KEY)"); storage.Query("CREATE TABLE `constraint_parameters` (`id` INTEGER PRIMARY KEY, `constraint` INT, `parameter` TEXT)"); storage.Query("CREATE TABLE `constraint_equations` (`id` INTEGER PRIMARY KEY, `constraint` INT, `equality` INT, `value` DOUBLE)"); storage.Query("CREATE TABLE `constraint_coefficients` (`id` INTEGER PRIMARY KEY, `equation` INT, `value` DOUBLE)"); for (int i = 0; i < d_constraints.Count; ++i) { ConstraintMatrix cons = d_constraints[i]; storage.Query(@"INSERT INTO `constraints` DEFAULT VALUES"); long cid = storage.LastInsertId; foreach (string p in cons.Parameters) { storage.Query(@"INSERT INTO `constraint_parameters` (`constraint`, `parameter`) VALUES (@0, @1)", cid, p); } foreach (Linear.Constraint eq in cons.Constraints) { storage.Query(@"INSERT INTO `constraint_equations` (`constraint`, `equality`, `value`) VALUES (@0, @1, @2)", cid, eq.Equality ? 1 : 0, eq.Value); long eqid = storage.LastInsertId; foreach (double coefficient in eq.Coefficients) { storage.Query(@"INSERT INTO `constraint_coefficients` (`equation`, `value`) VALUES (@0, @1)", eqid, coefficient); } } } }