Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
07/22/19 13:39:09 (5 years ago)
Author:
mkommend
Message:

#2971: Renamed views and updated error messages in constraint parser.

Location:
branches/2971_named_intervals
Files:
3 edited
2 moved

Legend:

Unmodified
Added
Removed
  • branches/2971_named_intervals/HeuristicLab.Problems.DataAnalysis.Views/3.4/HeuristicLab.Problems.DataAnalysis.Views-3.4.csproj

    r16896 r17146  
    325325      <DependentUpon>ModifiableDatasetView.cs</DependentUpon>
    326326    </Compile>
    327     <Compile Include="ParsedConstraintView.cs">
    328       <SubType>UserControl</SubType>
    329     </Compile>
    330     <Compile Include="ParsedConstraintView.designer.cs">
    331       <DependentUpon>ParsedConstraintView.cs</DependentUpon>
     327    <Compile Include="ProblemDataConstraintView.cs">
     328      <SubType>UserControl</SubType>
     329    </Compile>
     330    <Compile Include="ProblemDataConstraintView.designer.cs">
     331      <DependentUpon>ProblemDataConstraintView.cs</DependentUpon>
    332332    </Compile>
    333333    <Compile Include="Plugin.cs" />
  • branches/2971_named_intervals/HeuristicLab.Problems.DataAnalysis.Views/3.4/ProblemDataConstraintView.cs

    r17145 r17146  
    2929  [View("ParsedConstraint View")]
    3030  [Content(typeof(ProblemDataConstraint), true)]
    31   public partial class ParsedConstraintView : AsynchronousContentView {
    32     private CheckedItemList<IntervalConstraint> intervalConstraints;
     31  public partial class ProblemDataConstraintView : AsynchronousContentView {
     32    private readonly CheckedItemList<IntervalConstraint> intervalConstraints = new CheckedItemList<IntervalConstraint>();
    3333    public new ProblemDataConstraint Content {
    3434      get => (ProblemDataConstraint)base.Content;
     
    3636    }
    3737
    38     public ParsedConstraintView() {
     38    public ProblemDataConstraintView() {
    3939      InitializeComponent();
    4040      errorOutput.Text = "";
    41       intervalConstraints = new CheckedItemList<IntervalConstraint>();
    4241    }
    4342
     
    8887      if (Content == null) {
    8988        intervalConstraints.Clear();
    90         constraintsOutput.Content = intervalConstraints;
     89        intervalConstraintsView.Content = intervalConstraints;
    9190      } else {
    9291        intervalConstraints.Clear();
     
    9695        }
    9796
    98         constraintsOutput.Content = intervalConstraints;
     97        intervalConstraintsView.Content = intervalConstraints;
    9998      }
    10099    }
    101100
    102101    private void constraint_Changed(object sender, EventArgs e) {
    103       var constraint = (IntervalConstraint) sender;
     102      var constraint = (IntervalConstraint)sender;
    104103      intervalConstraints.SetItemCheckedState(constraint, constraint.Enabled);
    105104    }
     
    119118    private void constraint_CheckedItemChanged(object sender,
    120119      CollectionItemsChangedEventArgs<IndexedItem<IntervalConstraint>> e) {
    121       ICheckedItemList<IntervalConstraint> checkedItemList = (ICheckedItemList<IntervalConstraint>) sender;
     120      ICheckedItemList<IntervalConstraint> checkedItemList = (ICheckedItemList<IntervalConstraint>)sender;
    122121      foreach (var indexedItem in e.Items) {
    123122        indexedItem.Value.Enabled = checkedItemList.ItemChecked(indexedItem.Value);
  • branches/2971_named_intervals/HeuristicLab.Problems.DataAnalysis.Views/3.4/ProblemDataConstraintView.designer.cs

    r17145 r17146  
    2222
    2323namespace HeuristicLab.Problems.DataAnalysis.Views {
    24   partial class ParsedConstraintView {
     24  partial class ProblemDataConstraintView {
    2525    /// <summary>
    2626    /// Required designer variable.
     
    4646    /// </summary>
    4747    private void InitializeComponent() {
    48       System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(ParsedConstraintView));
     48      System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(ProblemDataConstraintView));
    4949      this.splitContainer1 = new System.Windows.Forms.SplitContainer();
    5050      this.groupBox1 = new System.Windows.Forms.GroupBox();
     
    5252      this.parseBtn = new System.Windows.Forms.Button();
    5353      this.label1 = new System.Windows.Forms.Label();
    54       //this.constraintsOutput = new System.Windows.Forms.Label();
    55       this.constraintsOutput = new HeuristicLab.Core.Views.CheckedItemListView<IntervalConstraint>();
     54      this.intervalConstraintsView = new HeuristicLab.Core.Views.CheckedItemListView<IntervalConstraint>();
    5655      this.errorOutput = new System.Windows.Forms.Label();
    5756      ((System.ComponentModel.ISupportInitialize)(this.splitContainer1)).BeginInit();
     
    7473      // splitContainer1.Panel2
    7574      //
    76       this.splitContainer1.Panel2.Controls.Add(this.constraintsOutput);
     75      this.splitContainer1.Panel2.Controls.Add(this.intervalConstraintsView);
    7776      this.splitContainer1.Size = new System.Drawing.Size(888, 629);
    7877      this.splitContainer1.SplitterDistance = 296;
     
    136135                         "5. Follow the steps 3-5 from above";
    137136      //
    138       // constraintsOutput
     137      // intervalConstraintsView
    139138      //
    140       this.constraintsOutput.Dock = System.Windows.Forms.DockStyle.Fill;
    141       this.constraintsOutput.Location = new System.Drawing.Point(3, 16);
    142       this.constraintsOutput.Name = "constraintsOutput";
    143       this.constraintsOutput.Size = new System.Drawing.Size(582, 587);
    144       this.constraintsOutput.TabIndex = 2;
     139      this.intervalConstraintsView.Dock = System.Windows.Forms.DockStyle.Fill;
     140      this.intervalConstraintsView.Location = new System.Drawing.Point(3, 16);
     141      this.intervalConstraintsView.Name = "intervalConstraintsView";
     142      this.intervalConstraintsView.Size = new System.Drawing.Size(582, 587);
     143      this.intervalConstraintsView.TabIndex = 2;
    145144      //
    146145      // errorOutput
     
    178177    private System.Windows.Forms.Button parseBtn;
    179178    private System.Windows.Forms.Label label1;
     179    private HeuristicLab.Core.Views.CheckedItemListView<IntervalConstraint> intervalConstraintsView;
    180180    private System.Windows.Forms.TextBox constraintsInput;
    181181    private System.Windows.Forms.Label errorOutput;
    182182
    183     //private System.Windows.Forms.Label constraintsOutput;
    184     private HeuristicLab.Core.Views.CheckedItemListView<IntervalConstraint> constraintsOutput;
    185183  }
    186184}
  • branches/2971_named_intervals/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/Interval/IntervalConstraintsParser.cs

    r16957 r17146  
    2828  public static class IntervalConstraintsParser {
    2929
    30     public static IEnumerable<IntervalConstraint> ParseInput(string input, string target = "", IEnumerable<string> variables = null) {
    31       var lines = input.Split(new[] { "\r\n", "\r", "\n" }, StringSplitOptions.None);
     30    public static IEnumerable<IntervalConstraint> ParseInput(string inputText, string target, IEnumerable<string> variables) {
     31
     32      if (string.IsNullOrEmpty(inputText)) throw new ArgumentNullException("No input text has been provided.");
     33      if (string.IsNullOrEmpty(target)) throw new ArgumentNullException("No target variable has been provided.");
     34      if (variables == null) throw new ArgumentNullException("No variables have been provided.");
     35      if (!variables.Any()) throw new ArgumentException("Varialbes are empty.");
     36
     37      var lines = inputText.Split(new[] { "\r\n", "\r", "\n" }, StringSplitOptions.None);
    3238      foreach (var line in lines) {
    3339        var trimmedLine = line.TrimStart();
     
    3642          var start = "Target:".Length;
    3743          var end = trimmedLine.Length;
    38           var targetConstraint = trimmedLine.Substring(start, end-start);
     44          var targetConstraint = trimmedLine.Substring(start, end - start);
    3945          var match = Regex.Match(targetConstraint,
    4046            @"(['](.*)[']|(.*[^\s]))\s*(\bin\b)\s*([\[\]])\s*(\S*)\s*(\.{2})\s*(\S*)\s*([\[\]])");
    4147          if (match.Success) {
    4248            if (match.Groups.Count != 10) {
    43               throw new ArgumentException("The given target-constraint is not complete!");
     49              throw new ArgumentException("The target-constraint is not complete.");
    4450            } else {
    4551              var targetVariable = match.Groups[1].Value.Trim();
     
    4753                targetVariable = targetVariable.Substring(1, targetVariable.Length - 2);
    4854              }
    49               if (target != "") {
    50                 if (targetVariable != target) {
    51                   throw new ArgumentException("The given target variable is not in the given dataset!");
    52                 }
     55
     56              if (targetVariable != target) {
     57                throw new ArgumentException($"The target variable {targetVariable}  does not match the provided target {target}.");
    5358              }
     59
    5460              var lowerBound = ParseIntervalBounds(match.Groups[6].Value);
    5561              var upperBound = ParseIntervalBounds(match.Groups[8].Value);
     
    6874            }
    6975          } else {
    70             throw new ArgumentException("The inserted target constraint is not valid!");
     76            throw new ArgumentException("The inserted target constraint is not valid.");
    7177          }
    7278          //Check for derivation
     
    7783          if (match.Success) {
    7884            if (match.Groups.Count != 17) {
    79               throw new ArgumentException("The given derivation-constraint is not complete");
     85              throw new ArgumentException("The given derivation-constraint is not complete.");
    8086            } else {
    8187              var derivationTarget = match.Groups[3].Value.Trim();
     
    8894                derivationVariable = derivationVariable.Substring(1, derivationVariable.Length - 2);
    8995              }
    90               if (target != "") {
    91                 if (derivationTarget != target)
    92                   throw new ArgumentException("The given target variable is not given in the dataset!");
     96
     97              if (derivationTarget != target) {
     98                throw new ArgumentException($"The target variable {derivationTarget}  does not match the provided target {target}.");
    9399              }
    94100
    95               if (variables != null && variables.Any()) {
    96                 if (variables.All(v => v != derivationVariable)) {
    97                   throw new ArgumentException("The given variable does not exist in the dataset!");
    98                 }
     101              if (variables.All(v => v != derivationVariable)) {
     102                throw new ArgumentException($"The given variable {derivationVariable} does not exist in the dataset.");
    99103              }
    100104
    101105              if (match.Groups[2].Value.Trim() != "" || match.Groups[11].Value.Trim() != "") {
    102106                if (match.Groups[2].Value.Trim() == "" || match.Groups[11].Value.Trim() == "")
    103                   throw new ArgumentException("Number of derivation has to be written on both sides!");
     107                  throw new ArgumentException("Number of derivation has to be written on both sides.");
    104108                if (match.Groups[2].Value.Trim() != match.Groups[11].Value.Trim())
    105                   throw new ArgumentException("Derivation number is not equal on both sides!");
     109                  throw new ArgumentException("Derivation number is not equal on both sides.");
    106110              }
    107111
     
    122126            }
    123127          } else {
    124             throw new ArgumentException("The inserted derivation constraint is not valid!");
     128            throw new ArgumentException("The inserted derivation constraint is not valid.");
    125129          }
    126130          //Check for comment
  • branches/2971_named_intervals/HeuristicLab.Problems.DataAnalysis/3.4/ProblemDataConstraint.cs

    r16959 r17146  
    2424using System.Collections.Generic;
    2525using System.Linq;
     26using HEAL.Attic;
    2627using HeuristicLab.Common;
    2728using HeuristicLab.Core;
    28 using HEAL.Attic;
    2929
    3030namespace HeuristicLab.Problems.DataAnalysis {
    3131  [StorableType("A56BFB05-8F11-4766-9FBF-20C7010F1CA3")]
    32   [Item("ParsedConstraint", "Represents parsed constraints.")]
     32  [Item("ProblemDataConstraints", "Represents constraints associated with a problem data.")]
    3333  public class ProblemDataConstraint : Item {
    3434    private static readonly string exampleInput = "# Example for a target variable constraint:" + Environment.NewLine +
     
    7676    }
    7777
    78     public ProblemDataConstraint() :base () {
     78    public ProblemDataConstraint() : base() {
    7979      this.Input = exampleInput;
    8080      this.constraints = new List<IntervalConstraint>();
Note: See TracChangeset for help on using the changeset viewer.