Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 41 additions & 1 deletion src/CyPhyPET/Rules/Global.cs
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,46 @@ public static IEnumerable<RuleFeedbackBase> UniqueTestBenchRefNames(CyPhy.Parame
.Concat(pet.Children.DriverCollection)
.Concat(pet.Children.ParametricExplorationCollection);

return UniqueNames(components);
return UniqueConstantsParametersAndOutputs(pet)
.Concat<RuleFeedbackBase>(UniqueNames(components));
}

public static IEnumerable<RuleFeedbackBase> UniqueConstantsParametersAndOutputs(CyPhy.ParametricExploration pet)
{
var result = new List<RuleFeedbackBase>();

var names = pet.Children.ConstantsCollection.SelectMany(
constants_block => constants_block.Children.MetricCollection.Select(
constant => new Tuple<string, string>(constant.Name, string.Format("{0}.{1} ({2})", constants_block.Name, constant.Name, constant.Kind))));
names = names.Concat(pet.Children.DriverCollection.SelectMany(
driver => driver.AllChildren.Where(
child => new List<string>() { typeof(CyPhyClasses.DesignVariable).Name, typeof(CyPhyClasses.IntermediateVariable).Name, typeof(CyPhyClasses.Objective).Name }.Contains(child.Kind)).Select(
child => new Tuple<string, string>(child.Name, string.Format("{0}.{1} ({2})", driver.Name, child.Name, child.Kind)))));

foreach (var group in names.GroupBy(variable => variable.Item1).Where(group => group.Count() > 1))
{
var feedback = new GenericRuleFeedback()
{
FeedbackType = FeedbackTypes.Warning,
InvolvedObjectsByRole = null,
Message = string.Format(
"PET requires unique names. Duplicate Names: {0}: {1}",
group.Key, String.Join(",", group.Select(pair => pair.Item2).ToArray()))
};
result.Add(feedback);
}
if (result.Count() > 0)
{
var feedback = new GenericRuleFeedback()
{
FeedbackType = FeedbackTypes.Warning,
InvolvedObjectsByRole = null,
Message = "Values in Merged PET file for variables with conflicting names may not get associated corretly"
};
result.Insert(0, feedback);
}

return result;
}

public static IEnumerable<RuleFeedbackBase> UniqueNames(IEnumerable<FCO> components)
Expand All @@ -155,6 +194,7 @@ public static IEnumerable<RuleFeedbackBase> UniqueNames(IEnumerable<FCO> compone
var feedback = new GenericRuleFeedback()
{
FeedbackType = FeedbackTypes.Error,
InvolvedObjectsByRole = null,
Message = string.Format("PET requires unique names. Duplicate names: {0}", String.Join(",", dupNames.ToArray()))
};
result.Add(feedback);
Expand Down