public PathSimplifier(SpaceInformation si, Goal goal, OptimizationObjective obj) : this(ompl_geometricPINVOKE.new_PathSimplifier__SWIG_0(SpaceInformation.getCPtr(si), Goal.getCPtr(goal), OptimizationObjective.getCPtr(obj)), true) { if (ompl_geometricPINVOKE.SWIGPendingException.Pending) { throw ompl_geometricPINVOKE.SWIGPendingException.Retrieve(); } }
public void TestOptimizationProblemContext() { var in1 = new ContinuousDimension("in_1", 0, 10); var in2 = new DiscreteDimension("in_2", 1, 20); var inputHypergrid = new Hypergrid("input", in1, in2); var out1 = new ContinuousDimension("out_1", -5, 7); var objectiveHypergrid = new Hypergrid("output", out1); var context1 = new DiscreteDimension("ctx_1", -100, -0); var contextHypergrid = new Hypergrid("context", context1); var objectives = new OptimizationObjective[] { new OptimizationObjective("out_1", true), new OptimizationObjective("nonExistent", false), }; var optimizationProblem = new OptimizationProblem(inputHypergrid, contextHypergrid, objectiveHypergrid, objectives); var serialized = OptimizerServiceEncoder.EncodeOptimizationProblem(optimizationProblem); var deserialized = OptimizerServiceDecoder.DecodeOptimizationProblem(serialized); Assert.Equal(optimizationProblem.ParameterSpace.Name, deserialized.ParameterSpace.Name); Assert.Equal(optimizationProblem.ObjectiveSpace.Name, deserialized.ObjectiveSpace.Name); Assert.Equal(optimizationProblem.ContextSpace.Name, deserialized.ContextSpace.Name); Assert.Equal(optimizationProblem.Objectives[0].Name, objectives[0].Name); Assert.Equal(optimizationProblem.Objectives[0].Minimize, objectives[0].Minimize); Assert.Equal(optimizationProblem.Objectives[1].Name, objectives[1].Name); Assert.Equal(optimizationProblem.Objectives[1].Minimize, objectives[1].Minimize); // This is not a rigorous test but it should be sufficient given the other tests in this set. Assert.Equal(optimizationProblem.ParameterSpace.Dimensions[0].Name, deserialized.ParameterSpace.Dimensions[0].Name); Assert.Equal(optimizationProblem.ParameterSpace.Dimensions[1].Name, deserialized.ParameterSpace.Dimensions[1].Name); Assert.Equal(optimizationProblem.ObjectiveSpace.Dimensions[0].Name, deserialized.ObjectiveSpace.Dimensions[0].Name); Assert.Equal(optimizationProblem.ContextSpace.Dimensions[0].Name, deserialized.ContextSpace.Dimensions[0].Name); }
public void setOptimizationObjective(OptimizationObjective optimizationObjective) { ompl_basePINVOKE.ProblemDefinition_setOptimizationObjective(swigCPtr, OptimizationObjective.getCPtr(optimizationObjective)); if (ompl_basePINVOKE.SWIGPendingException.Pending) { throw ompl_basePINVOKE.SWIGPendingException.Retrieve(); } }
public void setOptimized(OptimizationObjective opt, Cost cost, bool meetsObjective) { ompl_basePINVOKE.PlannerSolution_setOptimized(swigCPtr, OptimizationObjective.getCPtr(opt), Cost.getCPtr(cost), meetsObjective); if (ompl_basePINVOKE.SWIGPendingException.Pending) { throw ompl_basePINVOKE.SWIGPendingException.Retrieve(); } }
/// <summary> /// Convert optimization objective to protobuf instance. /// </summary> /// <param name="optimizationObjective"></param> /// <returns></returns> internal static OptimizerService.Objective ToOptimizerServiceObjective(this OptimizationObjective optimizationObjective) { return(new OptimizerService.Objective { Minimize = optimizationObjective.Minimize, Name = optimizationObjective.Name, }); }
public void computeEdgeWeights(OptimizationObjective opt) { ompl_basePINVOKE.PlannerData_computeEdgeWeights__SWIG_0(swigCPtr, OptimizationObjective.getCPtr(opt)); if (ompl_basePINVOKE.SWIGPendingException.Pending) { throw ompl_basePINVOKE.SWIGPendingException.Retrieve(); } }
public void extractMinimumSpanningTree(uint v, OptimizationObjective opt, PlannerData mst) { ompl_basePINVOKE.PlannerData_extractMinimumSpanningTree(swigCPtr, v, OptimizationObjective.getCPtr(opt), PlannerData.getCPtr(mst)); if (ompl_basePINVOKE.SWIGPendingException.Pending) { throw ompl_basePINVOKE.SWIGPendingException.Retrieve(); } }
public void setOptimizationObjective(OptimizationObjective optimizationObjective) { ompl_geometricPINVOKE.SimpleSetup_setOptimizationObjective(swigCPtr, OptimizationObjective.getCPtr(optimizationObjective)); if (ompl_geometricPINVOKE.SWIGPendingException.Pending) { throw ompl_geometricPINVOKE.SWIGPendingException.Retrieve(); } }
public void addObjective(OptimizationObjective objective, double weight) { ompl_basePINVOKE.MultiOptimizationObjective_addObjective(swigCPtr, OptimizationObjective.getCPtr(objective), weight); if (ompl_basePINVOKE.SWIGPendingException.Pending) { throw ompl_basePINVOKE.SWIGPendingException.Retrieve(); } }
public override Cost cost(OptimizationObjective obj) { Cost ret = new Cost(ompl_geometricPINVOKE.PathGeometric_cost(swigCPtr, OptimizationObjective.getCPtr(obj)), true); if (ompl_geometricPINVOKE.SWIGPendingException.Pending) { throw ompl_geometricPINVOKE.SWIGPendingException.Retrieve(); } return(ret); }
public virtual Cost cost(OptimizationObjective obj) { Cost ret = new Cost(ompl_basePINVOKE.Path_cost(swigCPtr, OptimizationObjective.getCPtr(obj)), true); if (ompl_basePINVOKE.SWIGPendingException.Pending) { throw ompl_basePINVOKE.SWIGPendingException.Retrieve(); } return(ret); }
public OptimizationObjective getObjective(uint idx) { global::System.IntPtr cPtr = ompl_basePINVOKE.MultiOptimizationObjective_getObjective(swigCPtr, idx); OptimizationObjective ret = (cPtr == global::System.IntPtr.Zero) ? null : new OptimizationObjective(cPtr, true); if (ompl_basePINVOKE.SWIGPendingException.Pending) { throw ompl_basePINVOKE.SWIGPendingException.Retrieve(); } return(ret); }
public OptimizationObjective getOptimizationObjective() { global::System.IntPtr cPtr = ompl_geometricPINVOKE.SimpleSetup_getOptimizationObjective(swigCPtr); OptimizationObjective ret = (cPtr == global::System.IntPtr.Zero) ? null : new OptimizationObjective(cPtr, true); if (ompl_geometricPINVOKE.SWIGPendingException.Pending) { throw ompl_geometricPINVOKE.SWIGPendingException.Retrieve(); } return(ret); }
public void TestOptimizationProblemNoContext() { var in1 = new ContinuousDimension("in_1", 0, 10); var in2 = new DiscreteDimension("in_2", 1, 20); var inputHypergrid = new Hypergrid("input", in1, in2); var out1 = new ContinuousDimension("out_1", -5, 7); var objectiveHypergrid = new Hypergrid("output", out1); var objectives = new OptimizationObjective[] { new OptimizationObjective("out_1", true), new OptimizationObjective("nonExistent", false), }; var optimizationProblem = new OptimizationProblem(inputHypergrid, objectiveHypergrid, objectives); var serialized = OptimizerServiceEncoder.EncodeOptimizationProblem(optimizationProblem); var deserialized = OptimizerServiceDecoder.DecodeOptimizationProblem(serialized); Assert.Null(deserialized.ContextSpace); }
internal static global::System.Runtime.InteropServices.HandleRef getCPtr(OptimizationObjective obj) { return((obj == null) ? new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero) : obj.swigCPtr); }
public OptimizationConstraint(OptimizationObjective constraint, PlanSetup plan) { _structureId = constraint.StructureId; if (constraint.GetType() == typeof(OptimizationPointObjective)) { OptimizationPointObjective temp = (OptimizationPointObjective)constraint; ConstraintType = typeof(OptimizationPointObjective); ConstraintTypeText = "Point"; Priority = temp.Priority; Operator = temp.Operator; if (Operator == OptimizationObjectiveOperator.Lower) { OperatorText = ">"; } else if (Operator == OptimizationObjectiveOperator.Upper) { OperatorText = "<"; } else if (Operator == OptimizationObjectiveOperator.Exact) { OperatorText = "="; } Dose = temp.Dose; Volume = temp.Volume; //calculate cost using weight = Priority^3 (Varian states that the function is proportional to Priority^n where n>2 so this should be close enough for approximating cost % since it is all relative to each other Cost = Math.Pow(Priority, 3) * Math.Pow(plan.GetDoseAtVolume(temp.Structure, Volume, VolumePresentation.Relative, DoseValuePresentation.Absolute).Dose - Dose.Dose, 2); } else if (constraint.GetType() == typeof(OptimizationMeanDoseObjective)) { OptimizationMeanDoseObjective temp = (OptimizationMeanDoseObjective)constraint; ConstraintType = typeof(OptimizationMeanDoseObjective); ConstraintTypeText = "Mean Dose"; Priority = temp.Priority; Dose = temp.Dose; //calculate cost using weight = Priority^3 (Varian states that the function is proportional to Priority^n where n>2 so this should be close enough for approximating cost % since it is all relative to each other Cost = Math.Pow(Priority, 3) * Math.Pow(plan.GetDVHCumulativeData(temp.Structure, DoseValuePresentation.Absolute, VolumePresentation.Relative, 0.01).MeanDose.Dose - Dose.Dose, 2); } else if (constraint.GetType() == typeof(OptimizationEUDObjective)) { OptimizationEUDObjective temp = (OptimizationEUDObjective)constraint; ConstraintType = typeof(OptimizationEUDObjective); ConstraintTypeText = "gEUD"; Priority = temp.Priority; Operator = temp.Operator; if (Operator == OptimizationObjectiveOperator.Lower) { OperatorText = ">"; } else if (Operator == OptimizationObjectiveOperator.Upper) { OperatorText = "<"; } else if (Operator == OptimizationObjectiveOperator.Exact) { OperatorText = "="; } Dose = temp.Dose; ParameterA = temp.ParameterA; //calculate gEUD using param a double gEUDSum = 0; for (double i = 0; i <= 100; i++) { gEUDSum += Math.Pow(plan.GetDoseAtVolume(temp.Structure, i, VolumePresentation.Relative, DoseValuePresentation.Absolute).Dose, ParameterA); } double gEUD = Math.Pow(1.0 / 100 * gEUDSum, 1 / ParameterA); //calculate cost using weight = Priority^3 (Varian states that the function is proportional to Priority^n where n>2 so this should be close enough for approximating cost % since it is all relative to each other Cost = Math.Pow(Priority, 3) * Math.Pow(gEUD - Dose.Dose, 2); } }
public static List <List <Structure> > SetConstraints(ref ExternalPlanSetup plan, HNPlan hnPlan, List <List <Structure> > matchingStructures, bool checkOptis = false) { StructureSet ss = plan.StructureSet; //Will be checking if opti structures need to be made. If so, they will be created and used for optimization. So we need a new matching list //which contains structures (opti or not) that are actually used during optimization. List <List <Structure> > optimizedStructures = new List <List <Structure> >(); if (!checkOptis) { optimizedStructures = new List <List <Structure> >(matchingStructures); for (int i = 0; i < hnPlan.ROIs.Count; i++) { hnPlan.ROIs[i].OptimizationStructures = new List <Structure>(hnPlan.ROIs[i].MatchingStructures); } return(optimizedStructures); } //Need to set all optimization constraints now. First clear all the current constraints foreach (var objective in plan.OptimizationSetup.Objectives.OfType <OptimizationPointObjective>()) { plan.OptimizationSetup.RemoveObjective(objective); } foreach (var objective in plan.OptimizationSetup.Objectives.OfType <OptimizationMeanDoseObjective>()) { plan.OptimizationSetup.RemoveObjective(objective); } //Now loop over all constraints and set them for (int i = 0; i < hnPlan.ROIs.Count; i++) //Loop over all structures { if (checkOptis) { hnPlan.ROIs[i].OptimizationStructures = new List <Structure>(); optimizedStructures.Add(new List <Structure>()); } for (int match = 0; match < matchingStructures[i].Count; match++) { //Here I want to make sure that the matched structure does not overlap with PTVs, and if it does I want to make an opti structure. if (checkOptis) { if (!hnPlan.ROIs[i].Critical) { Structure opti = CheckOverlap_OptiMaker(matchingStructures[i][match], ref ss, false); optimizedStructures[i].Add(opti); hnPlan.ROIs[i].OptimizationStructures.Add(opti); } else { Structure opti = CheckOverlap_OptiMaker(matchingStructures[i][match], ref ss, true); optimizedStructures[i].Add(opti); hnPlan.ROIs[i].OptimizationStructures.Add(opti); } } if (hnPlan.ROIs[i].OptimizationStructures[match].Volume < 0.5) { continue; } for (int j = 0; j < hnPlan.ROIs[i].Constraints.Count; j++) //Loop over all constraints for the current structure { plan.OptimizationSetup.AddNormalTissueObjective(80.0f, 0.0f, 100.0f, 40.0f, 0.05f); string type = hnPlan.ROIs[i].Constraints[j].Type; string subscript = hnPlan.ROIs[i].Constraints[j].Subscript; string relation = hnPlan.ROIs[i].Constraints[j].EqualityType; double value = hnPlan.ROIs[i].Constraints[j].Value; string format = hnPlan.ROIs[i].Constraints[j].Format; double volume = hnPlan.ROIs[i].OptimizationStructures[match].Volume; OptimizationObjectiveOperator constraintType; if (relation == "<") { constraintType = OptimizationObjectiveOperator.Upper; } else { constraintType = OptimizationObjectiveOperator.Lower; } if (type.ToLower() == "d") //if a dose constraint { try //subscript is a number { volume = Convert.ToInt32(subscript); //need to analyze DVH data if a number. //convert to cGy (90% of maximum for optimization) plan.OptimizationSetup.AddPointObjective(hnPlan.ROIs[i].OptimizationStructures[match], constraintType, new DoseValue(value, "cGy"), volume, hnPlan.ROIs[i].Constraints[j].Priority); } catch //is a mean or max restriction { if (subscript.ToLower() == "mean") { double dose = value * 0.9; //take 90 percent of dose constraint dose to start OptimizationObjective objective = plan.OptimizationSetup.AddMeanDoseObjective(hnPlan.ROIs[i].OptimizationStructures[match], new DoseValue(dose, "cGy"), hnPlan.ROIs[i].Constraints[j].Priority); //update subsegment constraints if organ is subsegmented if (hnPlan.ROIs[i].HasSubsegments) { //replace whole organ constraint with subsegment constraints //plan.OptimizationSetup.RemoveObjective(objective); //uncomment if don't also want the whole organ constraint foreach (Structure structure in ss.Structures) { if ((structure.Name.Contains(hnPlan.ROIs[i].OptimizationStructures[match].Name.Substring(0, 5))) && (structure.Name.ToLower().Contains("subseg"))) { plan.OptimizationSetup.AddMeanDoseObjective(structure, new DoseValue(dose, "cGy"), hnPlan.ROIs[i].Constraints[j].Priority); } } } } else if (subscript.ToLower() == "max") { double dose = value * 0.9; //take 90 percent of constraint dose to start if (hnPlan.ROIs[i].IsPTV) //if ptv, go halfway between the max dose and prescription dose { dose = (value + (double)hnPlan.ROIs[i].PTVDose) * 0.5; } OptimizationObjective objective = plan.OptimizationSetup.AddPointObjective(hnPlan.ROIs[i].OptimizationStructures[match], constraintType, new DoseValue(dose, "cGy"), 0, hnPlan.ROIs[i].Constraints[j].Priority); if (hnPlan.ROIs[i].HasSubsegments) { //replace whole organ constraint with subsegment constraints //plan.OptimizationSetup.RemoveObjective(objective); //uncomment if don't also want the whole organ constraint foreach (Structure structure in ss.Structures) { if ((structure.Name.Contains(hnPlan.ROIs[i].OptimizationStructures[match].Name.Substring(0, 5))) && (structure.Name.Contains("subseg"))) { plan.OptimizationSetup.AddPointObjective(hnPlan.ROIs[i].OptimizationStructures[match], constraintType, new DoseValue(dose, "cGy"), 0, hnPlan.ROIs[i].Constraints[j].Priority); } } } } else if (subscript.ToLower() == "min") { double dose = value * 1.05; //take 110% percent of constraint dose to start OptimizationObjective objective = plan.OptimizationSetup.AddPointObjective(hnPlan.ROIs[i].OptimizationStructures[match], constraintType, new DoseValue(dose, "cGy"), 100, hnPlan.ROIs[i].Constraints[j].Priority); if (hnPlan.ROIs[i].HasSubsegments) { //replace whole organ constraint with subsegment constraints //plan.OptimizationSetup.RemoveObjective(objective); //uncomment if don't also want the whole organ constraint foreach (Structure structure in ss.Structures) { if ((structure.Name.Contains(hnPlan.ROIs[i].OptimizationStructures[match].Name.Substring(0, 5))) && (structure.Name.Contains("subseg"))) { plan.OptimizationSetup.AddPointObjective(hnPlan.ROIs[i].OptimizationStructures[match], constraintType, new DoseValue(dose, "cGy"), 100, hnPlan.ROIs[i].Constraints[j].Priority); } } } } } } else if (type.ToLower() == "v") { try //in case can't parse the subscript into Int32 { if (format.ToLower() == "abs") //I assume here that an absolute volume constraint will always be an upper bound OAR consatraint { double dose = Convert.ToInt32(subscript); //convert to cGy //Need to convert to relative volume. volume = value / volume * 100; volume *= 0.9; //Make it an even harsher constraint if (volume <= 0.2) { volume = 0; } plan.OptimizationSetup.AddPointObjective(hnPlan.ROIs[i].OptimizationStructures[match], constraintType, new DoseValue(dose * 0.95, "cGy"), volume, hnPlan.ROIs[i].Constraints[j].Priority); } else //if relative, will belong to a PTV { double dose = StringOperations.FindPTVNumber(hnPlan.ROIs[i].OptimizationStructures[match].Name.ToLower()) * 100; volume = value; volume = 100; //set to 100 to push the optimizer plan.OptimizationSetup.AddPointObjective(hnPlan.ROIs[i].OptimizationStructures[match], constraintType, new DoseValue(dose, "cGy"), volume, hnPlan.ROIs[i].Constraints[j].Priority); } } catch { } } } } } return(optimizedStructures); }