internal PairwiseComparisonTerm(PairwiseComparison comparison, PairwiseParameter left, PairwiseParameter rightParam, PairwiseValue rightVal) : base(left) { if (rightVal == null && rightParam == null) { throw new ArgumentException("Can't have both val and param == null!"); } if (rightVal != null && rightParam != null) { throw new ArgumentException("Can't have both val and param non-null!"); } if (left == rightParam) { throw new ArgumentException("Can't have the same two parameters in the same comparison"); } this.rel = comparison; this.rhsValue = rightVal; this.rhsParameter = rightParam; if (rightVal != null && !this.Parameter.IsCompatibleWith(rightVal)) { throw new ArgumentException(string.Format("Mismatched types: {0} != {1}", left.PairwiseValueType, rightVal.PairwiseValueType)); } if (rightParam != null && !this.Parameter.IsCompatibleWith(rightParam)) { throw new ArgumentException(string.Format("Mismatched types: {0} != {1}", left.PairwiseValueType, rightParam.PairwiseValueType)); } if (!this.Parameter.IsCompatibleWith(rel)) { throw new NotSupportedException("Not supported: " + rel + " on " + this.Parameter + "; might be possible, though!"); } }
// warning: slow public PairwiseValue this[Type t] { get { PairwiseValue match = null; foreach (PairwiseValue v in this.values) { if (v.ValueType == t) { if (match != null) { throw new ArgumentException("Type " + t + " occurred multiple times"); } match = v; } } if (match != null) { return(match); } else { throw new IndexOutOfRangeException(t.FullName + " not found"); } } }
public PairwiseParameter(string name, string[] values) { this.name = name; foreach (string s in values) { this.AddValue(PairwiseValue.FromString(s)); } }
public bool Contains(PairwiseValue value) { if (value == null) { throw new ArgumentNullException("value"); } return(InnerList.Contains(value)); }
public static PairwiseValue CreateNegativeOption(PairwiseValue value) { if (value.IsNegative) { throw new ArgumentException(value + " already negative"); } return(CreateNegativeOption(value.value)); }
public void Insert(int index, PairwiseValue value) { if (value == null) { throw new ArgumentNullException("value"); } InnerList.Insert(index, value); }
public void Remove(PairwiseValue value) { if (value == null) { throw new ArgumentNullException("value"); } InnerList.Remove(value); }
public int Add(PairwiseValue value) { if (value == null) { throw new ArgumentNullException("value"); } return(InnerList.Add(value)); }
internal int Add(string name, PairwiseValue value) { Debug.Assert(value != null); Debug.Assert(name != null); ++last; Debug.Assert(names[last] == name); values[last] = value; isNegative = isNegative || value.IsNegative; return(last); }
protected override void OnValidate(object value) { base.OnValidate(value); PairwiseValue pvalue = value as PairwiseValue; if (pvalue == null) { throw new ArgumentException("PairwiseValue"); } }
string Quoted(PairwiseValue value) { if (value.PairwiseValueType == PairwiseValueType.Number) { return(context.LookupOutputValue(value)); } else { return('"' + context.LookupOutputValue(value) + '"'); } }
internal bool IsCompatibleWith(PairwiseValue value) { if (value == null) { return(false); } if (!setFirstType) { return(true); } return(this.PairwiseValueType == value.PairwiseValueType); }
// Rule support public PairwiseValue AddValue(PairwiseValue value) { if (!setFirstType) { firstType = value.PairwiseValueType; setFirstType = true; } if (value.PairwiseValueType != firstType) { throw new PairwiseException(string.Format("Type mismatch: {0} != {1}", this.firstType, value.ValueType, firstType)); } valueCollection.Add(value); return(value); }
public PairwiseTuple[] Generate(out PictExecutionInformation executionInformation) { string[][] results; string pictModel = (string)this.Visit(model); // PictConstants.Trace("Pict model: {0}", model.Comment); string fn = settings.CanCache ? PictConstants.CacheFileName : null; using (PictRunner exec = new PictRunner(fn)) { results = exec.MaybeExecutePict(settings, pictModel); executionInformation = exec.LastExecutionInformation; if (settings.RandomizeGeneration) { settings.RandomSeed = executionInformation.RandomSeed; // NOTE: not setting settings.RandomSeedSpecified } } // PictConstants.Trace("Results of executing PICT: {0}", results.Substring(0, Math.Min(255, results.Length))); int tupleLen = results[0].Length; PairwiseTuple[] tuples = new PairwiseTuple[results.Length - 1]; // skip the header string[] fields = results[0]; for (int tupleNumber = 0; tupleNumber < tuples.Length; ++tupleNumber) { // the line we access is actually '1-indexed': the first row is the fields string[] line = results[tupleNumber + 1]; PairwiseTuple pt = new PairwiseTuple(fields); for (int currentField = 0; currentField < tupleLen; ++currentField) { PairwiseValue value = context.FindValue(currentField, line[currentField]); pt.Add(model.Parameters[currentField].Name, value); } tuples[tupleNumber] = pt; } return(tuples); }
public override bool Equals(object obj) { PairwiseValue opt = obj as PairwiseValue; if (opt == null) { return(false); // throw? } if (opt == this) { return(true); } // note: considering negative but not weights or aliases return((opt.isNegative == this.isNegative) && // (opt.ValueType == this.ValueType) && // object.Equals(opt.value, this.value)); }
protected override void OnValidate(object val) { base.OnValidate(val); if (val == null) { throw new ArgumentNullException("value"); } PairwiseValue value = val as PairwiseValue; if (value == null) { throw new ArgumentException("Not a PairwiseValue, was a " + value.GetType().FullName); } if (value.ValueType != parent.ValueType) { throw new ArgumentException("Was a " + value.ValueType + "; expected " + parent.ValueType); } if (value.IsNegative != parent.IsNegative) { throw new ArgumentException(value + " IsNegative = " + value.IsNegative + " but expected " + parent.IsNegative); } // TBD: is this allowable? if (value.Aliases.Count != 0) { throw new ArgumentException("Attempted to do nested aliases: " + value.Aliases.Count + " present"); } if (this.Contains(value)) { throw new ArgumentException("Already contains " + value); } if (value.PairwiseValueType == PairwiseValueType.ComplexObject) { throw new NotSupportedException("Complex type comparison not yet supported"); } }
// NOTE: for PICT 3.0.34.0, the negative aliases are double-~'d, so we don't put them when we build the alias list public string LookupValuesAndAliases(PairwiseValue value) { if (value.Aliases.Count == 0) { return(LookupOutputValue(value)); } StringBuilder sb = new StringBuilder(100 + (20 * value.Aliases.Count)); sb.Append(LookupOutputValueWithoutWeight(value)); for (int i = 0, nminus1 = value.Aliases.Count - 1; i < value.Aliases.Count; ++i) { PairwiseValue alias = value.Aliases[i]; sb.Append(settings.AliasDelimiter); string q; if (i == nminus1) { // get the weight from the first value, not the second! q = LookupOutputValueWithWeight(alias, value.Weight); } else { q = LookupOutputValueWithoutWeight(alias); } if (q.StartsWith(settings.NegativePrefixString)) { // q = q.Substring(PictConstants.NegativeValuePrefixString.Length); sb.Append(q, settings.NegativePrefixString.Length, q.Length - settings.NegativePrefixString.Length); } else { sb.Append(q); } } return(sb.ToString()); }
public void Insert(int index, PairwiseValue value) { List.Insert(index, value); }
public string LookupInputValue(PairwiseValue valuex) { return(LookupWork(valuex, false, valuex.Weight)); }
public PairwiseLessThanTerm(PairwiseParameter parameter, PairwiseValue value) : base(PairwiseComparison.LessThan, parameter, null, value) { }
public string LookupOutputValue(PairwiseValue valuex) { return(LookupWork(valuex, true, valuex.Weight)); }
string LookupOutputValueWithWeight(PairwiseValue valuex, int weight) { return(LookupWork(valuex, true, weight)); }
public PairwiseNotEqualTerm NotEqual(PairwiseValue value) { return(new PairwiseNotEqualTerm(this, value)); }
public PairwiseLessThanOrEqualTerm LessThanOrEqual(PairwiseValue value) { return(new PairwiseLessThanOrEqualTerm(this, value)); }
public PairwiseLessThanTerm LessThan(PairwiseValue value) { return(new PairwiseLessThanTerm(this, value)); }
public PairwiseGreaterThanOrEqualTerm GreaterThanOrEqual(PairwiseValue value) { return(new PairwiseGreaterThanOrEqualTerm(this, value)); }
public int IndexOf(PairwiseValue value) { return(List.IndexOf(value)); }
public void RemoveValue(PairwiseValue value) { valueCollection.Remove(value); }
string LookupWork(PairwiseValue valuex, bool includeWeight, int weight) { string v; object vv = valuex.Value; switch (valuex.PairwiseValueType) { case PairwiseValueType.Enum: v = PictConstants.AggressivelyEscape(vv.ToString().Replace(',', ';')); break; case PairwiseValueType.String: // v = PictConstants.AggressivelyEscape(vv.ToString()); break; case PairwiseValueType.Number: // NOTE: here we fixed the german issue if (valuex.ValueType == typeof(Char)) { v = PictConstants.AggressivelyEscape(string.Format(PictConstants.Culture.NumberFormat, "{0}", vv)); } else { v = string.Format(PictConstants.Culture.NumberFormat, "{0}", vv); } break; case PairwiseValueType.ComplexObject: if (vv == null) { v = PictConstants.NullObjectString; } else { if (!objectLookup.ContainsKey(vv)) { // use the hex representation of the count v = string.Format(PictConstants.Culture, "o_{0:X}", objectLookup.Count); objectLookup[vv] = v; } else { v = ((string)objectLookup[vv]); } } break; default: throw new NotSupportedException("PairwiseValueType = " + valuex.PairwiseValueType); } if (settings.ContainsSpecialCharacters(v)) { throw new PairwiseException("Invalid characters in name: " + v); } if (valuex.IsNegative) { v = settings.NegativePrefix + v; } if (includeWeight && weight != PictConstants.DefaultWeight) { v = v + "(" + weight + ")"; } return(v); }
string LookupOutputValueWithoutWeight(PairwiseValue valuex) { return(LookupWork(valuex, false, valuex.Weight)); }