using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Graphs;

namespace Matching
{
    public class NodeLabelDistanceEditionAC : Label
    {
        /// <summary>
        /// List of the GXL attributes of the GraphComponent associated with this label
        /// </summary>
        public List<AttributeGXL> attributesGXL;
        public double NodeCost;

        /// <summary>
        /// Constructor. Initialize the list of GXL attributes
        /// </summary>
        public NodeLabelDistanceEditionAC()
		{
			attributesGXL = new List<AttributeGXL>();
            NodeCost = 1;
		}
        
        /// <summary>
        /// Getter and Setter of the GXL attributes list
        /// </summary>
        /// <param name="value">Set --> GXL attributes list</param>
        /// <returns>get --> GXL attributes list</returns>
		public List<AttributeGXL> AttributesGXL {
			get {
				return attributesGXL;
			}
			set {
				attributesGXL = value;
			}
		}

        /// <summary>
        /// Convert an attributes list to a string
        /// </summary>
        /// <returns> A string that contains the list of attributes</returns>
		#region implemented abstract members of Graphs.Label
		public override string toString ()
		{
			string s = "" + Id + ";";
			foreach (AttributeGXL att in this.AttributesGXL) 
            {
				s += att.Name + "=" + att.Value + ";";
			}
			return s;
		}

        /// <summary>
        /// Method to calculating the cost between two NodeLabelDistanceEditionAC
        /// </summary>
        /// <param name="label">LabelDistanceEditionto compare</param>
		public override double dissimilarity (Label label)
		{
            if (label is NodeLabelDistanceEditionAC )
            {

                //la suppression
                if (label.Id == ConstantsAC.EPS_ID)
                {
                    return NodeCost;
                }
               
                //l'insertion
                if (this.Id == ConstantsAC.EPS_ID)
                {
                    return NodeCost;
                }
                
                //la substitution
                return 0;
                //AttributeGXL x1att =this.attributesGXL.ElementAt(0);
                //AttributeGXL y1att = this.attributesGXL.ElementAt(1);

                //AttributeGXL x2att = ((NodeLabelDistanceEditionAC)label).attributesGXL.ElementAt(0);
                //AttributeGXL y2att = ((NodeLabelDistanceEditionAC)label).attributesGXL.ElementAt(1);

                //double x1 = Convert.ToDouble(x1att.Value, new System.Globalization.CultureInfo("EN"));//Double.Parse(x1att.Value);
                //double y1 = Convert.ToDouble(y1att.Value, new System.Globalization.CultureInfo("EN")); //Double.Parse(y1att.Value);
                //double x2 = Convert.ToDouble(x2att.Value, new System.Globalization.CultureInfo("EN"));//Double.Parse(x2att.Value);
                //double y2 = Convert.ToDouble(y2att.Value, new System.Globalization.CultureInfo("EN"));//Double.Parse(y2att.Value);
                //double res = Math.Sqrt(((x1 - x2) * (x1 - x2)) + ((y1 - y2) * (y1 - y2)));
                //double norm1 = Math.Sqrt((x1 * x1) + (y1 * y1));
                //double norm2 = Math.Sqrt((x2 * x2) + (y2 * y2));
                //return res;
                //return res / 1000.0;
                //res = res / Math.Max(norm1, norm2);
                //res = res * 1000;
                
                /*if(res <1000) {
                    return 0;
                }else{
                    return 1;
                }*/
                

                //la substitution
                /*if (this.Id == label.Id)
                {
                    return 0;
                }
                else
                {
                    return 1;
                }*/

               // return res;
                
            }
            return 0;
           

		}
	
		public override List<AttributeGXL> toAttributes ()
		{
			return this.AttributesGXL;
		}

		public override void fromAttributes (List<AttributeGXL> attributes)
		{
			this.AttributesGXL = attributes;
		}

		#endregion
    }
}
