public PermutationGA(int numberOFVariables, OptimizationType optimizationType, ObjectiveFunction <int> objectiveFunction, Panel hostPanelForMonitor = null) : base(numberOFVariables, optimizationType, objectiveFunction, hostPanelForMonitor) { m = new int[numberOFVariables]; n = new int[numberOFVariables]; }
private void RunAlgorithmButton_OnClick(object sender, RoutedEventArgs e) { KillRunning(); var resultDir = Path.Combine(OutputResultPath, OptimizationType.AsString() + "_" + (int)DateTime.Now.TimeOfDay.TotalMilliseconds); Directory.CreateDirectory(resultDir); GraphVisual.Canvas.SaveAsJpg(Path.Combine(resultDir, "graph.jpg"), 1); var solutions = Run(OptimizationType, GraphVisual.Graph); this.PrepareResultWindow(); this.WindowScrollViewer.ScrollToEnd(TimeSpan.FromSeconds(3.0)); SolutionsNavigator = PagesNavigator <GraphPartitionSolution> .Create(SetSolution, Dispatcher); SolutionsNavigator.StatusEvent += (o, args) => Dispatcher.InvokeAsync(() => { NextSolutionButton.IsEnabled = args.CanGoRight; PrevSolutionButton.IsEnabled = args.CanGoLeft; }); Task.Run(() => { foreach (var solution in solutions) { SolutionsNavigator.AddNext(solution); Thread.Sleep(100); Dispatcher.InvokeAsync(() => BestSolutionViewBox.Child.TypeCast <Canvas>().SaveAsJpg(Path.Combine(resultDir, solution.NegativePrice + ".jpg"), 1)); Thread.Sleep(100); } }); PauseButton.IsEnabled = true; }
private void OptimizationTypeChanged(OptimizationType optimizationType) { OptimizationType = optimizationType; StackPanel settingsStackPanel; switch (optimizationType) { case OptimizationType.Genetic: settingsStackPanel = InitGeneticSettings(); break; case OptimizationType.BranchAndBound: settingsStackPanel = InitBranchAndBoundSettings(); break; case OptimizationType.LocalSearch: settingsStackPanel = InitLocalSearchSettings(); break; default: throw new ArgumentOutOfRangeException(nameof(optimizationType), optimizationType, null); } settingsStackPanel.Children.Add(ShowVisual()); settingsStackPanel.Children.Add(InputGraphBullet()); settingsStackPanel.Children.Add(CreateGraphButton()); settingsStackPanel.Children.Add(OutputPathBullet()); SettingsViewer.Content = settingsStackPanel; }
static Model GenerateModelFromFile(List <string> data) { List <Constraint> constraints = new List <Constraint>(); List <SignRestriction> signRestrictions = new List <SignRestriction>(); string objectiveFunctionLine = data[0]; OptimizationType type = DetermineOptimizationType(objectiveFunctionLine); List <string> decisionVariables = GenerateDecisionVariables(objectiveFunctionLine); double[] objFunc = GenerateObjectiveFunction(objectiveFunctionLine); string signRestrictionsLine = data[data.Count - 1]; GenerateObjectiveFunction(objectiveFunctionLine); // we start at line 2 and end at second last line for (int i = 1; i < data.Count - 1; i++) { string constraintLine = data[i]; Constraint con = GenerateConstraint(constraintLine); if (con == null) { return(null); } constraints.Add(con); } signRestrictions = GenerateSignRestrictions(signRestrictionsLine); return(new Model(type, decisionVariables, objFunc, constraints, signRestrictions)); }
public DbOptimization GetOptimization(OptimizationType type, string sequence, int charge, string fragmentIon, int productCharge) { DbOptimization[] optimizations = Optimizations.Where(opt => Equals(opt.Type, (int)type) && Equals(opt.PeptideModSeq, sequence) && Equals(opt.Charge, charge) && Equals(opt.FragmentIon, fragmentIon) && Equals(opt.ProductCharge, productCharge)).ToArray(); return(optimizations.Count() == 1 ? optimizations.First() : null); }
public DbOptimization GetOptimization(OptimizationType type, Target sequence, Adduct charge, string fragmentIon, Adduct productCharge) { DbOptimization[] optimizations = Optimizations.Where(opt => Equals(opt.Type, (int)type) && Equals(opt.Target, sequence) && Equals(opt.Adduct, charge) && Equals(opt.FragmentIon, fragmentIon) && Equals(opt.ProductAdduct, productCharge)).ToArray(); return(optimizations.Length == 1 ? optimizations.First() : null); }
private void btnPSOcreate_Click(object sender, EventArgs e) { OptimizationType opty = theProblem.OptimizationGoal == COP.OptimizationType.Minimization ? OptimizationType.Minimization : OptimizationType.Maximization; PSOsolver = new PSOforCOP(theProblem.Dimension, theProblem.UpperBound, theProblem.LowerBound, theProblem.GetObjectiveValue); propertyGridPSO.SelectedObject = PSOsolver; btnPSOReset.Enabled = true; }
public OptimizationKey(OptimizationType optType, Target peptideModSeq, Adduct precursorAdduct, string fragmentIon, Adduct productAdduct) { OptType = optType; PeptideModSeq = peptideModSeq; PrecursorAdduct = precursorAdduct; FragmentIon = fragmentIon; ProductAdduct = productAdduct; }
public Model(OptimizationType optimizationType, List <string> decisionVariables, double[] objectiveFunction, List <Constraint> constraints, List <SignRestriction> signRestrictions) { this.OptimizationType = optimizationType; this.DecisionVariables = decisionVariables; this.ObjectiveFunction = objectiveFunction; this.Constraints = constraints; this.SignRestrictions = signRestrictions; }
public OptimizationKey(OptimizationType optType, string peptideModSeq, int charge, string fragmentIon, int productCharge) { OptType = optType; PeptideModSeq = peptideModSeq; Charge = charge; FragmentIon = fragmentIon; ProductCharge = productCharge; }
public static void Initialise(OptimiserParameters optimiserParameters, StrategyBase strategy) { _minimumTrades = optimiserParameters.MinimumTrades; _maximumTrades = optimiserParameters.MaximumTrades; _optimisationType = (OptimizationType) Activator.CreateInstance(Type.GetType(optimiserParameters.FitnessFunctionType)); _optimisationType.Strategy = strategy; }
public static void Initialise(OptimiserParameters optimiserParameters, StrategyBase strategy) { _minimumTrades = optimiserParameters.MinimumTrades; _maximumTrades = optimiserParameters.MaximumTrades; _optimisationType = (OptimizationType)Activator.CreateInstance(Type.GetType(optimiserParameters.FitnessFunctionType)); _optimisationType.Strategy = strategy; }
private void btnCreateBASOLVER_Click(object sender, EventArgs e) { OptimizationType opty = theProblem.OptimizationGoal == COP.OptimizationType.Minimization ? OptimizationType.Minimization : OptimizationType.Maximization; BAsolver = new BAforCOP(theProblem.Dimension, theProblem.UpperBound, theProblem.LowerBound, opty, theProblem.GetObjectiveValue); propertyGridBA.SelectedObject = BAsolver; btnBAReset.Enabled = true; }
public NotGettingBetter(Cooler cooler, OptimizationType optimizationType, uint maxSteps, uint notGettingBetterDuration = 1000) { _bestSolValue = optimizationType == OptimizationType.Maximization ? double.MinValue : double.MaxValue; _cooler = cooler; _notGettingBetterDuration = notGettingBetterDuration; _optimizationType = optimizationType; _maxSteps = maxSteps; }
public HybridACOGA(int numberOfVariables, OptimizationType opType, GA <int> .ObjectiveFunctionDelegate objectFunction, double[,] distance) : base(numberOfVariables, opType, objectFunction) { getObjectiveValue = objectFunction; numberOfCity = numberOfVariables; FromToDistanceMatrix = distance; // Allocate memory for pheromone matrix and heuristic value matrix // Heuristic values in the matrix are computed and assigned via // the specified function delegate pheromone = new double[numberOfCity, numberOfCity]; indicesOfAnts = new int[populationSize]; solutions = new int[populationSize][]; soFarTheBestSoluiton = new int[numberOfCity]; for (int r = 0; r < numberOfCity; r++) { for (int c = 0; c < numberOfCity; c++) { pheromone[r, c] = 0.01; } } for (int r = 0; r < numberOfCity; r++) { for (int c = 0; c < numberOfCity; c++) { AverageDistance += FromToDistanceMatrix[r, c]; } } AverageDistance = AverageDistance / (numberOfCity * numberOfCity); heuristicValues = new double[numberOfCity, numberOfCity]; for (int r = 0; r < numberOfCity; r++) { for (int c = 0; c < numberOfCity; c++) { heuristicValues[r, c] = DistanceInverseHeuristic(r, c); } } for (int i = 0; i < populationSize; i++) { indicesOfAnts[i] = i; solutions[i] = new int[numberOfCity]; for (int j = 0; j < numberOfCity; j++) { solutions[i][j] = j; } KnuthShuffle(solutions[i]); } // Allocate memory for the arries used in ACO, whose length is // depend on the number of variables. In contrast, those arraies // with length depending on the number of ants are allocated in // reset function. probabilities = new double[numberOfCity]; candidateSet = new int[numberOfCity]; ObjectiveValues = new double[populationSize]; // Set drop amount multiplier; which is the avarage length //dropMultiplier = dropPheromone * dropMultiplier / getObjectiveValue(objectiveValues); }
public BAforCOP(int numberOfPreys, double[] upBound, double[] lowBound, OptimizationType type, ObjectiveFunction objFun) { this.numberOfPreys = numberOfPreys; lowerBound = lowBound; upperBound = upBound; optimizationTpe = type; //完全讓constructor決定就好 objFunction = objFun; soFarTheBestSolution = new double[numberOfPreys]; }
public GasesBrownianMotionOptimization(IFitFunction function, OptimizationType optimizationType, int numAgents, int numDimensions, int maxIteration, double minSearchValue, double maxSearchValue) { MaxIteration = maxIteration; NumAgents = numAgents; NumDimensions = numDimensions; MinSearchValue = minSearchValue; MaxSearchValue = maxSearchValue; Function = function; OptimizationType = optimizationType; }
/// <summary> /// To employ a GA solver, user must provide the number of variables, the optimization type, and a function delegate /// that compute and return the objective value for a given solution. /// </summary> /// <param name="numberOfVariables"> Number of variables of the problem</param> /// <param name="opType"> The optimization problem type </param> /// <param name="objectFunction"> The function delegate that computer the objective value for a given solution </param> public GA(int numberOfVariables, OptimizationType opType, GA <T> .ObjectiveFunctionDelegate objectFunction) { numberOfGenes = numberOfVariables; optimizationType = opType; if (objectFunction == null) { throw new Exception("You must prepare an objective function."); } GetObjectiveValueFunction = objectFunction; }
public DbOptimization GetOptimization(OptimizationType type, string seq, int charge, string fragment, int productCharge) { RequireUsable(); var key = new OptimizationKey(type, seq, charge, fragment, productCharge); double value; return((_database.DictLibrary.TryGetValue(new OptimizationKey(type, seq, charge, fragment, productCharge), out value)) ? new DbOptimization(key, value) : null); }
public GravitationalSearchAlgorithm(IFitFunction function, OptimizationType optimizationType, int numAgents, int numDimensions, int maxIteration, double minSearchValue, double maxSearchValue) { MaxIteration = maxIteration; NumAgents = numAgents; NumDimensions = numDimensions; MinSearchValue = minSearchValue; MaxSearchValue = maxSearchValue; Function = function; OptimizationType = optimizationType; }
private double zeta = 0.02; // Total Cost of Empire = Cost of Imperialist + Zeta * mean(Cost of All Colonies) //https://www.researchgate.net/post/Can-anyone-help-me-with-the-Imperialist-Competitive-Algorithm public ImperialistCompetitiveAlgorithm(IFitFunction function, OptimizationType optimizationType, int numCountry, int numImperialist, int numDimensions, int maxIteration, double minSearchValue, double maxSearchValue) { MaxIteration = maxIteration; NumCountry = numCountry; NumDimensions = numDimensions; MinSearchValue = minSearchValue; MaxSearchValue = maxSearchValue; Function = function; NumImperialist = numImperialist; OptimizationType = optimizationType; }
public Criterion(OptimizationType optimizationType, ObjectiveAggregator <T> objectiveAggr, ConstraintAggregator <T> constraintAggr) { if (!Enum.IsDefined(typeof(OptimizationType), optimizationType)) { throw new InvalidEnumArgumentException(nameof(optimizationType), (int)optimizationType, typeof(OptimizationType)); } _objectiveAggr = objectiveAggr ?? throw new ArgumentNullException(nameof(objectiveAggr)); _constraintAggr = constraintAggr ?? throw new ArgumentNullException(nameof(constraintAggr)); OptimizationType = optimizationType; }
public ConditionalHeat(Cooler cooler, OptimizationType optimizationType, uint maxSteps, float heatBackByPercent, ushort clock = 100) { _clock = clock; _counter = clock; _cooler = cooler; _maxSteps = maxSteps; _optimizationType = optimizationType; _heatBackByPercent = heatBackByPercent; _bestSolValue = _optimizationType == OptimizationType.Maximization ? double.MinValue : double.MaxValue; TotalSteps = 0; }
public Heater(Cooler cooler, OptimizationType optimizationType, uint maxSteps, float heatBackToPercent, double minTemp = 1e-6) { _cooler = cooler; _prevMaxTemp = cooler.InitialTemperature; _maxSteps = maxSteps; _optimizationType = optimizationType; _heatBackToPercent = heatBackToPercent; _minTemp = minTemp; _bestSolValue = _optimizationType == OptimizationType.Maximization ? double.MinValue : double.MaxValue; TotalSteps = 0; StepsSinceReheat = 0; }
static Model GenerateSampleModel() { OptimizationType type = OptimizationType.max; List <string> decVars = new List <string>() { "x1", "x2" }; double[] objFunc = { 100, 30 }; List <Constraint> constraints = GenerateSampleConstraints(); List <SignRestriction> restrictions = GenerateSampleSignRestrictions(); return(new Model(type, decVars, objFunc, constraints, restrictions)); }
private OptimizationFunction SelectFunction(OptimizationType type) { switch (type) { case OptimizationType.SDG: Program = OpenDM.Gpgpu.ProgramOption.Create(typeof(OpenDM.Gpgpu.Source.Optimizer_SDG_01).Name); return(SDG); case OptimizationType.Adam: Program = OpenDM.Gpgpu.ProgramOption.Create(typeof(OpenDM.Gpgpu.Source.Optimizer_Adam_01).Name); return(Adam); default: return(null); } }
public static void Optimized(List <DeviceOptimization> devices, OptimizationType type) { List <Period> zones = DefineZone(type); foreach (var device in devices.Where(x => x.IsAvailable)) { foreach (var day in device.Device.DayOfWeek) { List <Period> newPeriods = new List <Period>(); foreach (var period in day.Periods) { OptimizeOnePeriod(period, newPeriods, zones); } day.Periods = newPeriods; } } }
private static List <Period> DefineZone(OptimizationType type) { List <Period> zones = null; switch (type) { case OptimizationType.TwoZone: zones = new List <Period>() { Period.SetZone(new TimeSpan(0, 0, 0, 0), new TimeSpan(0, 7, 0, 0)), Period.SetZone(new TimeSpan(0, 23, 0, 0), new TimeSpan(0, 23, 59, 59)) }; break; case OptimizationType.ThreeZone: zones = new List <Period>() { Period.SetZone(new TimeSpan(0, 0, 0, 0), new TimeSpan(0, 7, 0, 0)), Period.SetZone(new TimeSpan(0, 23, 0, 0), new TimeSpan(0, 23, 59, 59)) }; break; } return(zones); }
/// <summary> /// Converts the <see cref="sourceValue" /> parameter to the <see cref="destinationType" /> parameter using <see cref="formatProvider" /// /> and <see cref="ignoreCase" /> /// </summary> /// <param name="sourceValue">the <see cref="System.Object"/> to convert from</param> /// <param name="destinationType">the <see cref="System.Type" /> to convert to</param> /// <param name="formatProvider">not used by this TypeConverter.</param> /// <param name="ignoreCase">when set to <c>true</c>, will ignore the case when converting.</param> /// <returns> /// an instance of <see cref="OptimizationType" />, or <c>null</c> if there is no suitable conversion. /// </returns> public override object ConvertFrom(object sourceValue, global::System.Type destinationType, global::System.IFormatProvider formatProvider, bool ignoreCase) => OptimizationType.CreateFrom(sourceValue);
private void FillTree() { Dictionary <string, long> dictHierarchyCardinality = new Dictionary <string, long>(); try { AdomdRestrictionCollection restrictions = new AdomdRestrictionCollection(); restrictions.Add(new AdomdRestriction("CATALOG_NAME", this.liveDB.Name)); restrictions.Add(new AdomdRestriction("CUBE_NAME", this.liveCube.Name)); restrictions.Add(new AdomdRestriction("HIERARCHY_VISIBILITY", 3)); //visible and non-visible hierarchies foreach (System.Data.DataRow r in adomdConnection.GetSchemaDataSet("MDSCHEMA_HIERARCHIES", restrictions).Tables[0].Rows) { dictHierarchyCardinality.Add(Convert.ToString(r["HIERARCHY_UNIQUE_NAME"]), Convert.ToInt64(r["HIERARCHY_CARDINALITY"])); } } catch { } StringBuilder sbExport = new StringBuilder(); sbExport.Append("Cube Dimension Name").Append("\t").Append("Attribute Name").Append("\t").Append("Number of Slices on this Attribute").Append("\t").Append("Attribute Cardinality").Append("\t").Append("Related Partition Count").Append("\t").Append("Currently Effective Optimized State").Append("\t").Append("Recommendation").AppendLine(); foreach (CubeDimension cd in cloneCube.Dimensions) { TreeNode parentNode = treeViewAggregation.Nodes.Add(cd.Name); parentNode.Tag = cd; parentNode.ImageIndex = parentNode.SelectedImageIndex = 0; bool bAllIndexesChecked = true; foreach (CubeAttribute ca in cd.Attributes) { if (ca.AttributeHierarchyEnabled && ca.Attribute.AttributeHierarchyEnabled) { CubeAttribute caSliced = null; foreach (CubeAttribute sliced in dictHitIndexes.Keys) { if (sliced.Parent.ID == ca.Parent.ID && sliced.AttributeID == ca.AttributeID) { caSliced = sliced; break; } } string sNodeName = ca.Attribute.Name; int iIndexHits = 0; if (caSliced != null) { iIndexHits = dictHitIndexes[caSliced]; sNodeName += " (Index hits: " + iIndexHits.ToString("g") + ")"; } TreeNode attributeNode = parentNode.Nodes.Add(sNodeName); attributeNode.Tag = ca; attributeNode.ImageIndex = attributeNode.SelectedImageIndex = 1; attributeNode.Checked = (caSliced == null); bAllIndexesChecked = bAllIndexesChecked && attributeNode.Checked; bool bInEnabledHierarchy = false; foreach (CubeHierarchy ch in ca.Parent.Hierarchies) { foreach (Microsoft.AnalysisServices.Level l in ch.Hierarchy.Levels) { if (l.SourceAttributeID == ca.AttributeID && ch.Enabled && ch.OptimizedState == OptimizationType.FullyOptimized) { bInEnabledHierarchy = true; } } } OptimizationType optimized = ca.Attribute.AttributeHierarchyOptimizedState; if (optimized == OptimizationType.FullyOptimized) { optimized = ca.AttributeHierarchyOptimizedState; } if (optimized == OptimizationType.NotOptimized && bInEnabledHierarchy) { optimized = OptimizationType.FullyOptimized; } string sRecommendation = ""; if (optimized == OptimizationType.FullyOptimized && iIndexHits == 0) { attributeNode.ForeColor = Color.Black; sRecommendation = "Disable"; attributeNode.BackColor = Color.Green; attributeNode.ToolTipText = "Currently indexed but the index was not used during the profiler trace. If left checked, BIDS Helper will disable the indexes when you click OK."; } else if (optimized == OptimizationType.NotOptimized) { attributeNode.ForeColor = Color.DarkGray; attributeNode.ToolTipText = "Indexes not currently being built."; if (iIndexHits > 0) { sRecommendation = "Enable"; attributeNode.ForeColor = Color.Black; attributeNode.BackColor = Color.Red; attributeNode.ToolTipText = "Currently not indexed but the queries observed during the profiler trace would have used the index if it had been built. If left unchecked, BIDS Helper will re-enable indexing when you click OK."; } } else { attributeNode.ForeColor = Color.Black; attributeNode.ToolTipText = "Indexes are being built and are used during the queries observed during the profiler trace."; } long? iCardinality = null; string sAttributeUniqueName = "[" + ca.Parent.Name + "].[" + ca.Attribute.Name + "]"; if (dictHierarchyCardinality.ContainsKey(sAttributeUniqueName)) { iCardinality = dictHierarchyCardinality[sAttributeUniqueName]; } int iPartitions = 0; try { foreach (MeasureGroup mg in liveCube.MeasureGroups) { if (mg.Dimensions.Contains(cd.ID)) { try { RegularMeasureGroupDimension rmgd = mg.Dimensions[cd.ID] as RegularMeasureGroupDimension; if (rmgd == null) { continue; } if (!AggManager.ValidateAggs.IsAtOrAboveGranularity(ca.Attribute, rmgd)) { continue; } iPartitions += mg.Partitions.Count; } catch { } } } } catch { } sbExport.Append(cd.Name).Append("\t").Append(ca.Attribute.Name).Append("\t").Append(iIndexHits).Append("\t").Append(iCardinality).Append("\t").Append(iPartitions).Append("\t").Append(optimized.ToString()).Append("\t").Append(sRecommendation).AppendLine(); } } parentNode.Checked = bAllIndexesChecked; } treeViewAggregation.Sort(); sExport = sbExport.ToString(); }
public bool HasType(OptimizationType type) { return(GetOptimizations().Any(opt => Equals(opt.Type, (int)type))); }
public DbOptimization(OptimizationType type, string seq, int charge, string fragmentIon, int productCharge, double value) { Key = new OptimizationKey(type, seq, charge, fragmentIon, productCharge); Value = value; }
public DbOptimization GetOptimization(OptimizationType type, string seq, int charge, string fragment, int productCharge) { RequireUsable(); var key = new OptimizationKey(type, seq, charge, fragment, productCharge); double value; return (_database.DictLibrary.TryGetValue(new OptimizationKey(type, seq, charge, fragment, productCharge), out value)) ? new DbOptimization(key, value) : null; }
public DbOptimization GetOptimization(OptimizationType type, string seq, int charge) { return GetOptimization(type, seq, charge, null, 0); }
public bool HasType(OptimizationType type) { return GetOptimizations().Any(opt => Equals(opt.Type, (int) type)); }