/// <summary> /// Găsește valoarea intersecției unui termen fuzzy cu valoarea unei proprietăți a unui serviciu (ce poate fi fuzzy sau crisp). /// </summary> /// <param name="service">Serviciul de care aparține proprietatea</param> /// <param name="property">Proprietatea a cărei valoare se va folosi pentru intersecție</param> /// <param name="shape">Termenul care se intersectează cu valoarea proprietății</param> /// <returns>Valoarea intersecției celor 2 termeni</returns> public static double intersect(Service service, Property property, Term shape) { try { bool isLowerBetter = shape.start > shape.end || property.start > property.end; double start2 = isLowerBetter ? shape.end : shape.start; double left2 = isLowerBetter ? shape.right : shape.left; double right2 = isLowerBetter ? shape.left : shape.right; double end2 = isLowerBetter ? shape.start : shape.end; if (service.isFuzzy(property)) { Term term = service.getFuzzyValue(property); if (term == null) { return double.NaN; } double result = intersectLinesY(term.start, term.left, 0.0, 1.0, start2, left2, 0.0, 1.0); result = Math.Max(result, intersectLinesY(term.left, term.right, 1.0, 1.0, start2, left2, 0.0, 1.0)); result = Math.Max(result, intersectLinesY(term.right, term.end, 1.0, 0.0, start2, left2, 0.0, 1.0)); result = Math.Max(result, intersectLinesY(term.start, term.left, 0.0, 1.0, left2, right2, 1.0, 1.0)); result = Math.Max(result, intersectLinesY(term.left, term.right, 1.0, 1.0, left2, right2, 1.0, 1.0)); result = Math.Max(result, intersectLinesY(term.right, term.end, 1.0, 0.0, left2, right2, 1.0, 1.0)); result = Math.Max(result, intersectLinesY(term.start, term.left, 0.0, 1.0, right2, end2, 1.0, 0.0)); result = Math.Max(result, intersectLinesY(term.left, term.right, 1.0, 1.0, right2, end2, 1.0, 0.0)); return Math.Max(result, intersectLinesY(term.right, term.end, 1.0, 0.0, right2, end2, 1.0, 0.0)); } else { double crispValue = service.getCrispValue(property); if (double.IsNaN(crispValue)) { return double.NaN; } if (crispValue > start2 && crispValue < left2) { return (crispValue - start2) / (left2 - start2); } else { if (crispValue >= left2 && crispValue <= right2) { return 1.0; } else { if (crispValue > right2 && crispValue < end2) { return (crispValue - end2) / (right2 - end2); } else { return 0.0; } } } } } catch (Exception) { return double.NaN; } }
/// <summary> /// Returnează toate proprietățile unui serviciu într-o formă afișabilă. /// </summary> /// <param name="service">Serviciul a cărui proprietăți se caută</param> /// <returns>Proprietățile, fiecare sub formă de string lizibil</returns> public string[] getPrintableProperties(Service service) { try { if (service.functionality != null) { Property[] properties = service.functionality.properties; string[] result = new string[properties.Length]; for (int i = 0; i < result.Length; ++i) { result[i] = properties[i].name + " [" + (service.isFuzzy(properties[i]) ? "fuzzy:" + service.getFuzzyValue(properties[i]).name : "crisp:" + service.getCrispValue(properties[i])) + "]"; } return result; } else { return service.getAllNamesAndValues(); } } catch (Exception) { return new string[0]; } }