public void TestInclusiveRange(long minInclusive, long maxInclusive, string expectedType)
        {
            var xsd = @$ "<?xml version=" "1.0" " encoding=" "UTF-8" "?>
<xs:schema elementFormDefault=" "qualified" " xmlns:xs=" "http://www.w3.org/2001/XMLSchema" ">
	<xs:complexType name="     "document" ">
    <xs:sequence>
		  <xs:element name="         "someValue" ">
			  <xs:simpleType>
				  <xs:restriction base="                 "xs:integer" ">
            <xs:minInclusive value=" "{minInclusive}" "/>
            <xs:maxInclusive value=" "{maxInclusive}" "/>
				  </xs:restriction>
			  </xs:simpleType>
		  </xs:element>
    </xs:sequence>
	</xs:complexType>
</xs:schema>";

            var generatedType = ConvertXml(nameof(TestTotalDigits), xsd, new Generator
            {
                NamespaceProvider = new NamespaceProvider
                {
                    GenerateNamespace = key => "Test"
                }
            });

            var expectedProperty = $"public {expectedType} SomeValue";

            Assert.Contains(expectedProperty, generatedType.First());
        }
Esempio n. 2
0
 public void wipeNetwork()
 {
     this.networkTree = null;
     foreach (Broker.Broker n in _brokers)
     {
         if (n.getExecuting())
         {
             n.closeProcess();
         }
     }
     _brokers.Clear();
     foreach (Publisher.Publisher n in _publishers)
     {
         if (n.getExecuting())
         {
             n.closeProcess();
         }
     }
     _publishers.Clear();
     foreach (Subscriber.Subscriber n in _subscribers)
     {
         if (n.getExecuting())
         {
             n.closeProcess();
         }
     }
     _subscribers.Clear();
 }
Esempio n. 3
0
    private void OnTriggerEnter(Collider other)
    {
        //AttackAreaのついている攻撃が来たら属性を調べる
        if (other.gameObject.GetComponent <AttackArea>())
        {
            AttackMagic = other.gameObject.GetComponent <AttackArea>();

            //プレイヤーの攻撃でしか壊せない
            if (AttackMagic.aligment == aligment.player)
            {
                Attackele = AttackMagic.element.type;
                //全ての攻撃で壊れるbool
                if (ALL || Attackele == Weakele)
                {
                    GetDamage(AttackMagic.Damage);
                    if (_HP <= 0)
                    {
                        SEManager.SetSE(destSE);
                        //HPを減らす攻撃であれば壊れる
                        Destroy(gameObject);
                    }
                }
            }
        }
    }
        public void TestFallbackType(int totalDigits, bool useTypeAsFallback, string expectedType)
        {
            var xsd = @$ "<?xml version=" "1.0" " encoding=" "UTF-8" "?>
<xs:schema elementFormDefault=" "qualified" " xmlns:xs=" "http://www.w3.org/2001/XMLSchema" ">
	<xs:complexType name="     "document" ">
    <xs:sequence>
		  <xs:element name="         "someValue" ">
			  <xs:simpleType>
				  <xs:restriction base="                 "xs:integer" ">
            <xs:totalDigits value=" "{totalDigits}" "/>
				  </xs:restriction>
			  </xs:simpleType>
		  </xs:element>
    </xs:sequence>
	</xs:complexType>
</xs:schema>";

            var generatedType = ConvertXml(nameof(TestTotalDigits), xsd, new Generator
            {
                NamespaceProvider = new NamespaceProvider
                {
                    GenerateNamespace = key => "Test"
                },
                IntegerDataType = typeof(long),
                UseIntegerDataTypeAsFallback = useTypeAsFallback
            });

            var expectedProperty = $"public {expectedType} SomeValue";

            Assert.Contains(expectedProperty, generatedType.First());
        }
Esempio n. 5
0
 public Card(string name, int price, element elemnt, int damage)
 {
     this.SetName(name);
     this.SetPrice(price);
     this.SetElement(elemnt);
     this.SetDamage(damage);
 }
Esempio n. 6
0
        public void CreateSchemaTest()
        {
            var schema     = new schema();
            var globalAttr = new attribute(new topLevelAttribute()
            {
                name = "name"
            });

            var globalEl = new element(new topLevelElement()
            {
                name        = "anElement",
                complexType = new localComplexType()
                {
                    attribute = { new attributeType()
                                  {
                                      @ref = new XmlQualifiedName("name")
                                  } }
                }
            });

            schema.attribute.Add(globalAttr);
            schema.element.Add(globalEl);

            Assert.IsNotEmpty(schema.attribute);
            Assert.IsNotEmpty(schema.element);
        }
    public int CompareTo(object obj)
    {
        // throws exception if type is wrong
        element other = (element)obj;

        return(priority.CompareTo(other.priority));
    }
Esempio n. 8
0
 public void reload()
 {
     string[] templines = IO.File.ReadAllLines(path);
     { //removing coments
         string[] t;
         int      c = 0;
         foreach (string s in templines)
         {
             if (!(s.StartsWith(comment) || string.IsNullOrWhiteSpace(s)))
             {
                 c++;
             }
         }
         t = new string[c];
         int cc = 0;
         foreach (string s in templines)
         {
             if (!(s.StartsWith(comment) || string.IsNullOrWhiteSpace(s)))
             {
                 t[cc] = s; cc++;
             }
         }
         templines = t;
     }
     listset = new element[templines.Length];
     for (int x = 0; x != listset.Length; x++)
     {
         listset[x]       = new element();
         listset[x].value = templines[x];
     }
 }
Esempio n. 9
0
        public void Inc(uint key)
        {
            uint hsh = hash(key);

            if (_buckets[hsh] == null)
            {
                _buckets[hsh] = new element[1] {
                    new element {
                        _key = key, _value = 1
                    }
                };
                return;
            }

            foreach (var elem in _buckets[hsh])
            {
                if (elem._key == key)
                {
                    elem._value++;
                    return;
                }
            }

            var e = new element[_buckets[hsh].Length + 1];

            Array.Copy(_buckets[hsh], 0, e, 1, _buckets[hsh].Length);
            _buckets[hsh] = e;
            e[0]          = new element {
                _key = key, _value = 1
            };
        }
Esempio n. 10
0
        /// <summary>
        ///   Gets the elements for the given class.
        /// </summary>
        public IEnumerable <element> GetElementsFor(@class cls)
        {
            List <element> items = new List <element>();

            // Add class items if any
            if (cls.element != null)
            {
                items.AddRange(cls.element);
            }

            // Add extension items if any
            IEnumerable <element> extensionItems = this.GetClassExtensionFor(cls).Where(c => c.element != null).SelectMany(c => c.element);

            if (extensionItems != null)
            {
                items.AddRange(extensionItems);
            }

            // Retrieve the base class if any
            @class baseClass = null;
            String type      = cls.inherits;

            if (type != null)
            {
                baseClass = (from c in this.Classes
                             where (c.id != null && String.Equals(c.id, type)) ||
                             (c.id == null && String.Equals(c.name, type))
                             select c).FirstOrDefault();
            }

            // Filter out elements to avoid override
            if (baseClass != null && baseClass.element != null)
            {
                IEnumerable <element> baseElements = this.GetElementsFor(baseClass);
                foreach (element item in items)
                {
                    if (item.hidden)
                    {
                        continue;
                    }
                    element baseItem = baseElements.FirstOrDefault(e => String.Equals(e.type, item.type));
                    if (baseItem != null)
                    {
                        continue;
                    }
                    yield return(item);
                }
            }
            else
            {
                foreach (element item in items)
                {
                    if (item.hidden)
                    {
                        continue;
                    }
                    yield return(item);
                }
            }
        }
Esempio n. 11
0
        public void Add(ulong low, ulong high, T value)
        {
            uint hsh = hash(low, high);

            element[] e;
            if (_buckets[hsh] == null)
            {
                _buckets[hsh] = e = new element[1];
            }
            else
            {
                e = new element[_buckets[hsh].Length + 1];
                Array.Copy(_buckets[hsh], 0, e, 1, _buckets[hsh].Length);
                _buckets[hsh] = e;
            }
            e[0] = new element {
                _high = high, _low = low, _value = value
            };

            /*
             * if (e.Length > 6)
             * {
             *  Console.WriteLine("bad collision! Hash: " + hsh);
             *  foreach (var el in e)
             *      Console.WriteLine("- {0} {1}".Fmt(el._low.ToString("X16"), el._high.ToString("X16")));
             * }
             */
        }
        void rev_branch(element e2, element e3, element e1)
        {
            Vector3 b2         = e2.getThreeDPos() - e1.getThreeDPos();
            Vector3 b3         = e3.getThreeDPos() - e1.getThreeDPos();
            Vector3 midbottom2 = e1.getThreeDPos() + Vector3.Project(0.5F * b2, p);
            Vector3 midbottom3 = e1.getThreeDPos() + Vector3.Project(0.5F * b3, p);
            Vector3 midbottom;

            if ((midbottom2 - e1.getThreeDPos()).magnitude < (midbottom3 - e1.getThreeDPos()).magnitude)
            {
                midbottom = midbottom2;
            }
            else
            {
                midbottom = midbottom3;
            }
            Vector3 midtop2 = midbottom + b2 - Vector3.Project(b2, p);
            Vector3 midtop3 = midbottom + b3 - Vector3.Project(b3, p);

            lines.Add(new line(midbottom, e1.getThreeDPos()));
            lines.Add(new line(midtop2, midbottom));
            lines.Add(new line(midtop3, midbottom));
            lines.Add(new line(e2.getThreeDPos(), midtop2));
            lines.Add(new line(e3.getThreeDPos(), midtop3));
        }
Esempio n. 13
0
        public void Add(ulong key, T value)
        {
            uint hsh = hash(key);

            element[] e;
            if (_buckets[hsh] == null)
            {
                _buckets[hsh] = e = new element[1];
            }
            else
            {
                foreach (var elem in _buckets[hsh])
                {
                    if (elem._key == key)
                    {
                        elem._value = value;
                        return;
                    }
                }
                e = new element[_buckets[hsh].Length + 1];
                Array.Copy(_buckets[hsh], 0, e, 1, _buckets[hsh].Length);
                _buckets[hsh] = e;
            }
            e[0] = new element {
                _key = key, _value = value
            };
        }
Esempio n. 14
0
        private static void SortByFreqInefficient(int[] arr)
        {
            int[] op = new int[arr.Length];
            Dictionary <int, element> dict   = new Dictionary <int, element>();
            List <element>            lstEle = new List <element>();

            for (int i = 0; i < arr.Length; i++)
            {
                if (!dict.ContainsKey(arr[i]))
                {
                    element e = new element(arr[i], i);
                    dict.Add(arr[i], e);
                    lstEle.Add(e);
                    heapify(lstEle);
                }
                else
                {
                    dict[arr[i]].freq++;
                    siftDown(lstEle, 0, lstEle.Count - 1);
                }

                op[i] = lstEle[0].val;
            }

            for (int i = 0; i < op.Length; i++)
            {
                Console.WriteLine("arr[{0}] = {1}", i, op[i]);
            }
        }
Esempio n. 15
0
 public override void on_anchor_click(string url, element el)
 {
     if (url != null)
     {
         make_url(url, _base_url, out _clicked_url);
     }
 }
Esempio n. 16
0
        static void siftDown(List <element> arr, int start, int end)
        {
            int root = start;

            while ((2 * root + 1) <= end)
            {
                int child = 2 * root + 1;
                int swap  = root;

                if (arr[swap].freq < arr[child].freq)
                {
                    swap = child;
                }

                if ((child + 1) <= end && arr[swap].freq < arr[child + 1].freq)
                {
                    swap = child + 1;
                }

                if (swap != root)
                {
                    element temp = arr[swap];
                    arr[swap] = arr[root];
                    arr[root] = temp;
                    root      = swap;
                }
                else
                {
                    return;
                }
            }
        }
Esempio n. 17
0
    //Carga datos guardados en local
    public void loadLocalData()
    {
        // Aqui hay que meter un trycatch con carga default si no se encuentra
        try
        {
            string savePath = Path.Combine(Application.persistentDataPath, "SaveData");
            // Obtenemos las lineas separadas por fin de linea
            string[] lines = File.ReadAllText(savePath).Split('\n');

            /*// Guardamos numero de habitacion
             * room = lines[0][0];*/
            string[] objectsRead = lines[1].Split(',');
            invObjects = new List <element>();
            if (objectsRead.Length > 0)
            {
                for (int i = 0; i < objectsRead.Length; i++)
                {
                    element elem = new element(objectsRead[i].Split(':')[0], (objectState)int.Parse(objectsRead[i].Split(':')[1]));
                    invObjects.Add(elem);
                }
            }
            string[] sceneRead = lines[2].Split(',');
            sceneObjs = new List <element>();
            if (sceneRead.Length > 0)
            {
                for (int i = 0; i < sceneRead.Length; i++)
                {
                    element elem = new element(sceneRead[i].Split(':')[0], (objectState)int.Parse(sceneRead[i].Split(':')[1]));
                    sceneObjs.Add(elem);
                }
            }
        }
        catch { loadRoomFromFile(room); }
    }
Esempio n. 18
0
    // ---Constructor---
    public Skill(skillType type, string atkName, string description, element atkElement, int mpCost,
                 int range, float start, float end, SpriteAnimation anim, string sfxPath)
    {
        // Set main variables
        this.type        = type;
        this.atkName     = atkName;
        this.description = description;
        this.atkElement  = atkElement;
        this.mpCost      = mpCost;
        this.range       = range;

        // Set animation variables
        this.startDist = start;
        this.endDist   = end;
        this.anim      = anim;

        // Set sfx
        this.sfxPath = sfxPath;
        if (sfxPath != "null")
        {
            sfx = Resources.Load(sfxPath) as AudioClip;
        }

        return;
    }
    /// <summary>
    /// 属性タブボタン
    /// </summary>
    /// <param name="num">属性のボタン</param>
    public void ElementButtonClick(int num)
    {
        element ele = (element)System.Enum.ToObject(typeof(element), num);

        //bulletFrame.color = ConstData.GetElementColor (ele);
        magickManager.SetElement(ele);
        folders.GetValue(ele).transform.SetSiblingIndex(2);
    }
Esempio n. 20
0
 public override bool appendChild(element el)
 {
     if (el == null)
     {
         return(false);
     }
     return(el.get_tagName() == "tbody" || el.get_tagName() == "thead" || el.get_tagName() == "tfoot" ? appendChild(el) : false);
 }
Esempio n. 21
0
            private static @string String(this element i)
            {
                if (i >= element(len(_element_index) - 1L))
                {
                    return("element(" + strconv.FormatInt(int64(i), 10L) + ")");
                }

                return(_element_name[_element_index[i].._element_index[i + 1L]]);
Esempio n. 22
0
 void Start()
 {
     if (ElementClass == ElementType.None)
     {
         return;
     }
     _element = new element(transform);
 }
Esempio n. 23
0
 /// <param name="d">degat</param>
 /// <param name="o">or</param>
 /// <param name="p">pv</param>
 public Monstre(int dmg, int gold, int life, element element)
 {
     degat = dmg;
     or    = gold;
     Pv    = life;
     pvmax = life;
     elem  = element;
 }
Esempio n. 24
0
    //Methods

    public element[] Aggregation(IList <element> element, int i)
    {
        element[] arrelements = new element[3] {
            element[i], element[i + 1], element[i + 2]
        };
        element[i].Orientation     = 'X';
        element[i + 1].Orientation = 'Y';
        element[i + 2].Orientation = 'Z';
        return(arrelements);
    }
Esempio n. 25
0
    public Point3d yFsPoint(element element, Point3d origin)
    {
        Point3d Fspot = new Point3d();

        Fspot.X = origin.X;
        Fspot.Y = element.Length * 0.5 + origin.Y;
        Fspot.Z = origin.Z;

        return(Fspot);
    }
Esempio n. 26
0
        public override bool appendChild(element el)
        {
            if (el == null)
            {
                return(false);
            }
            var tagName = el.get_tagName();

            return(tagName == "tbody" || tagName == "thead" || tagName == "tfoot" ? base.appendChild(el) : false);
        }
Esempio n. 27
0
 /// <summary>
 /// 攻撃を受けた際の処理
 /// </summary>
 /// <param name="value">受けるダメージ</param>
 /// <param name="damageType">ダメージの属性</param>
 /// <returns></returns>
 public float TakeDamage(EnemyController target, float value, element damageType)
 {
     for (int i = 0; i < states.Length; i++)
     {
         if (states[i].HasValue)
         {
             value = states[i].Value.TakeDamage(target, value, damageType);
         }
     }
     return(value);
 }
        void elbow(element e1, element e2)
        {
            Debug.Log("ELBOWING");
            Vector3 b         = e2.getThreeDPos() - e1.getThreeDPos();
            Vector3 midbottom = e1.getThreeDPos() + Vector3.Project(0.5F * b, p);
            Vector3 midtop    = midbottom + b - Vector3.Project(b, p);

            lines.Add(new line(e1.getThreeDPos(), midbottom));
            lines.Add(new line(midbottom, midtop));
            lines.Add(new line(midtop, e2.getThreeDPos()));
        }
Esempio n. 29
0
    public void AddToStat(statType stat, element element, int increment)
    {
        switch (stat)
        {
        case statType.Damage:
        {
            fixedDamageStats[element] += increment;
            break;
        }

        case statType.DamagePercent:
        {
            percentDamageStats[element] += increment;
            break;
        }

        case statType.Res:
        {
            fixedResStats[element] += increment;
            break;
        }

        case statType.Health:
        {
            health += increment;
            break;
        }

        case statType.Slime:
        {
            slime += increment;
            break;
        }

        case statType.ActionPoints:
        {
            actionPoints += increment;
            break;
        }

        case statType.ExpPool:
        {
            expPool += increment;
            break;
        }

        case statType.ElementSlots:
        {
            elementSlots += increment;
            break;
        }
        }
    }
Esempio n. 30
0
            public void removeall()
            {
                element temp = first;
                element help;

                while (temp != null)
                {
                    help = temp;
                    temp = temp.Next;
                    remove(help.Member);
                }
            }
Esempio n. 31
0
	public Skill (string unique, int _class, int lvl, string name, string desc, damage_type dmgType, damage_effect dmgEffect, element e, int turnM, int dm, int mpC, int hpC = 0){
		unique = uName;
		reqClass = _class;
		dType = dmgType;
		dEffect = dmgEffect;
		turnMod = turnM;
		_name = name;
		_desc = desc;
		dmg = dm;
		hpCost = hpC;
		mpCost = mpC;
		level = lvl;
		el = e;

	}
Esempio n. 32
0
            public int net_size; //SOM網路大小: net_size*net_size

            #endregion Fields

            #region Constructors

            public net(int d, int size)
            {
                element.total = 0;
                Random rand = new Random();
                net_size = size;
                dim = d;
                input = new double[d];

                cell = new element[size, size];
                for (int i = 0; i < size; i++)
                    for (int j = 0; j < size; j++)
                        cell[i, j] = new element(d, ref rand);
            }
Esempio n. 33
0
    static void Main()
    {
        Console.BufferHeight = Console.WindowHeight = 20;
        Console.BufferWidth = Console.WindowWidth = 60;

        int lives = 5;
        int speed = 100;
        int scoreVar = 0;
        element dwarf = new element();
        dwarf.x = 9;
        dwarf.y = Console.WindowHeight - 1;
        dwarf.c = '#';
        dwarf.color = ConsoleColor.Yellow;

        Random rGenerator = new Random();
        List<element> elements=new List<element>();
        char[] symbols = { '@', '%', '&', '!', '*', '$','O' };
        ConsoleColor [] colors= {ConsoleColor.White,ConsoleColor.Green,ConsoleColor.Red};

        while (true)
        {
            bool hitted = false;
            //User Control
            while(Console.KeyAvailable)
            {

                ConsoleKeyInfo pressedKey = Console.ReadKey(true);
                if (pressedKey.Key==ConsoleKey.LeftArrow)
                {
                    if(dwarf.x - 1 >= 0){
                    dwarf.x -= 1;
                    }
                }
                else if (pressedKey.Key == ConsoleKey.RightArrow)
                {
                    if(dwarf.x+1 <= 19){
                    dwarf.x += 1;
                    }
                }
            }
            if(speed<270)
            {
            speed++;
            }

            //Element's creating
            int chance = rGenerator.Next(1,100);
            if (chance < 5)
            {
                element rock = new element();
                rock.x = rGenerator.Next(0, 20);
                rock.y = 0;
                rock.c = symbols[6];
                rock.color = colors[rGenerator.Next(0, 3)];
                elements.Add(rock);
            }
            else if (chance<10)
            {
                element rock = new element();
                rock.x = rGenerator.Next(0, 20);
                rock.y = 0;
                rock.c = symbols[4];
                rock.color = colors[rGenerator.Next(0, 3)];
                elements.Add(rock);
            }
            else if(chance<30)
            {
                element rock = new element();
                rock.x = rGenerator.Next(0, 20);
                rock.y = 0;
                rock.c = symbols[5];
                rock.color = colors[rGenerator.Next(0, 3)];
                elements.Add(rock);
            }
            else
            {
                element rock = new element();
                rock.x = rGenerator.Next(0, 20);
                rock.y = 0;
                rock.c = symbols[rGenerator.Next(0, 4)];
                rock.color = colors[rGenerator.Next(0, 3)];
                elements.Add(rock);
            }
            //Score Counting
            scoreVar++;

            //Console Clearing
            Console.Clear();

            //Console Redraw
            List<element> newElements=new List<element>();
            for (int i = 0; i < elements.Count; i++ )
            {
                element oldElement = elements[i];
                element newElement =new element();
                newElement.x = oldElement.x;
                newElement.y =oldElement.y + 1;
                newElement.c = oldElement.c;
                newElement.color = oldElement.color;
                if(newElement.y==dwarf.y && newElement.x==dwarf.x)
                {
                    if (newElement.c == '*')
                    {
                        if(speed>=50)
                        {
                        speed = speed - 50;
                        }
                    }
                    else if(newElement.c=='$')
                    {
                        scoreVar = scoreVar + 50;
                    }
                    else if(newElement.c=='O')
                    {
                        lives++;
                    }
                    else
                    {
                        hitted = true;
                        lives--;
                    }
                }
                if(newElement.y<Console.WindowHeight)
                {

                newElements.Add(newElement);
                }
            }
            elements = newElements;
            foreach (var rocks in elements)
            {
                PrintOnPosition(rocks.x, rocks.y, rocks.c, rocks.color);
            }

            if (hitted)
            {
                Console.Beep();
                elements.Clear();
                PrintOnPosition(dwarf.x, dwarf.y, 'X', ConsoleColor.Red);
            }
            else
            {
                PrintOnPosition(dwarf.x, dwarf.y, dwarf.c, dwarf.color);
            }

            for (int i = 0; i < Console.WindowHeight; i++)
            {
                PrintOnPosition(20, i, '|', ConsoleColor.White);
            }
            //Print Info
            if(lives==0)
            {
                PrintStringOnPosition(20, 6, "GAME OVER!!!");
                PrintStringOnPosition(20, 7, "Your Score is:" + scoreVar + "\n\n");
                return;
            }

            PrintStringOnPosition(32, 0, "FallingRocks", ConsoleColor.Yellow);

            PrintStringOnPosition(34, 2, "Score:" + scoreVar);

            PrintStringOnPosition(34, 4, "Lives:"+lives);

            PrintStringOnPosition(34, 6, "Speed:"+speed);

            PrintStringOnPosition(25, 10, "Hints: O are extra life!",ConsoleColor.Yellow);
            PrintStringOnPosition(32, 11, "$ are extra points!", ConsoleColor.Yellow);
            PrintStringOnPosition(32, 12, "* are speed slow down!", ConsoleColor.Yellow);
            Thread.Sleep(400-speed);
        }
    }
Esempio n. 34
0
        private void WireSets()
        {
            foreach (string tableToWire in FkForTables.Keys)
            {
                logger.Debug(string.Format("{0} working on:", GetType().Name) + tableToWire);
                Dictionary<string,int> multicolls = new Dictionary<string,int>();
                var kinfo = FkForTables[tableToWire];
                foreach (var key in kinfo.Keys)
                {
                    var kdef = kinfo[key];
                    ITableMetadata ptable = GetPrimaryTable(kdef);
                    ITableMetadata ctable = GetForeignTable(kdef);

                    if (null != ptable)
                    {
                        var collectingClass = context.Model.GetClassFromTableName(ptable.Name);
                        var collectedClass = context.Model.GetClassFromTableName(ctable.Name);
                        if (null == collectedClass)
                            logger.Warn(string.Format("Not included table {0} could not be used in a collection", ctable.Name));
                        if (null == collectingClass)
                            logger.Warn(string.Format("Target table for a collection of {0} is not included", ptable.Name));
                        if (null != collectedClass && null != collectingClass)
                        {

                            if (!multicolls.ContainsKey(collectedClass.name))
                                multicolls[collectedClass.name] = 0;
                            set s = new set();
                            s.inverse = true;
                            context.Model.AddCollectionToEntity(collectingClass.name, s);
                            s.table = collectedClass.table;
                            s.name = context.NamingStrategy.GetNameForCollection(collectedClass.name, multicolls[collectedClass.name]);
                            s.key = GenerateCollectionKey(kdef);

                            var pkctable = GetKeyColumns(ctable);
                            if (pkctable.Length > 0) // collected object is an entity
                            {
                                s.Item = new onetomany() { @class = context.Model.GetClassFromTableName(ctable.Name).name };
                            }
                            else
                            {
                                var notanentity = context.Model.GetClassFromTableName(ctable.Name);
                                property[] props = context.Model.GetPropertyOfEntity(notanentity.name);
                                if (props.Length == 1)
                                {
                                    //use an element
                                    element e = new element();
                                    e.column = props[0].column ?? props[0].name;
                                    e.type1 = props[0].type1;
                                    e.type = props[0].type;
                                    e.precision = props[0].precision;
                                    e.length = props[0].length;
                                    s.Item = e;
                                }
                                else
                                {
                                    //use a composite element
                                    compositeelement ce = new compositeelement();
                                    ce.@class = context.NamingStrategy.GetClassNameForCollectionComponent(ctable.Name);
                                    ce.Items = context.Model.GetPropertyOfEntity(notanentity.name);
                                    s.Item = ce;
                                }
                                context.Model.RemoveEntity(notanentity.name);
                            }
                        }
                    }
                }
            }
        }
 private void CheckIfCanBeMap(set set, @class entity)
 {
     if (set.Item is onetomany)
     {
         var collectedEntity = context.Model.GetClassFromEntityName((set.Item as onetomany).@class);
         if (collectedEntity.Item is compositeid)
         {
             var cid = collectedEntity.Item as compositeid;
             List<string> setColumn = new List<string>();
             if (!string.IsNullOrEmpty(set.key.column1))
                 setColumn.Add(set.key.column1);
             if (null != set.key.column)
                 setColumn.AddRange(set.key.column.Select(q => q.name));
             List<string> collectedKeyColumns = new List<string>();
             collectedKeyColumns.AddRange(cid.Items.OfType<keyproperty>().Select(q => q.column1 ?? q.name));
             List<string> nonOverlappingColumns;
             if (CheckOverlapping(setColumn, collectedKeyColumns, out nonOverlappingColumns))
             {
                 setToRemove.Add(set);
                 entitiesToRemove.Add(collectedEntity.name);
                 map map = new map();
                 map.name = set.name;
                 map.table = set.table;
                 map.key = set.key;
                 var meta = context.GetTableMetaData(collectedEntity.schema, collectedEntity.table ?? collectedEntity.name);
                 if (nonOverlappingColumns.Count == 1)
                 {
                     map.Item = new index() { column1 = nonOverlappingColumns[0], type = typeConverter.GetNHType(meta.GetColumnMetadata(nonOverlappingColumns[0])) };
                 }
                 else
                 {
                     compositeindex ci = new compositeindex();
                     ci.@class = context.NamingStrategy.GetClassNameForComponentKey(map.name??map.table);
                     ci.Items = nonOverlappingColumns.Select(q => new keyproperty() {
                             name = context.NamingStrategy.GetPropertyNameFromColumnName(q)
                            ,column1 = context.NamingStrategy.GetPropertyNameFromColumnName(q) != q ? q : null
                            ,type1=typeConverter.GetNHType(meta.GetColumnMetadata(q))
                            ,length = meta.GetColumnMetadata(q).ColumnSize == 0 ? null:meta.GetColumnMetadata(q).ColumnSize.ToString()
                     }).ToArray();
                     map.Item = ci;
                 }
                 property[] props = collectedEntity.Items.OfType<property>().ToArray();
                 if (props.Length == 1)
                 {
                     //use an element
                     element e = new element();
                     e.column = props[0].column ?? props[0].name;
                     e.type1 = props[0].type1;
                     e.type = props[0].type;
                     e.precision = props[0].precision;
                     e.length = props[0].length;
                     map.Item1 = e;
                 }
                 else
                 {
                     //use a composite element
                     compositeelement ce = new compositeelement();
                     ce.@class = context.NamingStrategy.GetClassNameForCollectionComponent(collectedEntity.table??collectedEntity.name);
                     ce.Items = context.Model.GetPropertyOfEntity(collectedEntity.name);
                     map.Item1 = ce;
                 }
                 context.Model.AddCollectionToEntity(entity.name, map);
             }
         }
     }
 }
Esempio n. 36
0
        private void button3_Click(object sender, EventArgs e)
        {
            //執行RBF運算
            iter = int.Parse(textBox2.Text);
            neuronNUM = int.Parse(textBox1.Text);
            Unit = max_dis / half_height;
            threshold = double.Parse(textBox4.Text);
            learning_rate = double.Parse(textBox9.Text);

            //配置初始鍵結值
            Random rand = new Random();
            element[] neuron = new element[neuronNUM];//神經元

            //每個神經元作初始化
            for (int a = 0; a < neuronNUM; a++)
            {
                neuron[a] = new element(dim, ref rand);
                //neuron[a].sigma = double.Parse(textBox3.Text);
                neuron[a].sigma = s[a];
            }
            for (int b = 0; b < neuronNUM; b++)
                for (int c = 0; c < dim; c++)
                    neuron[b].ANNmean[c] = mean[b][c];

            textBox5.Text += " 初始平均值 " + Environment.NewLine;
            textBox6.Text += " 初始鍵結值 " + Environment.NewLine;
            textBox7.Text += " 初始標準差 " + Environment.NewLine;
            textBox8.Text += " 初始閥值 " + Environment.NewLine;
            for (int i = 0; i < neuron.Length; i++)
            {
                textBox5.Text += neuron[i].ANNmean[0] + " , " + neuron[i].ANNmean[1] + Environment.NewLine;
                textBox6.Text += neuron[i].weight + Environment.NewLine;
                textBox7.Text += neuron[i].sigma + Environment.NewLine;
            }
            textBox8.Text += threshold+Environment.NewLine;

            //畫圖工具的初始

            Bitmap windowRBF = new Bitmap(pictureBox1.Size.Width, pictureBox1.Size.Height);
            windowRBF = window.Clone() as Bitmap;
            Graphics graph = Graphics.FromImage(windowRBF);
            graph.PageUnit = GraphicsUnit.Pixel;
            graph.TranslateTransform((int)half_height, (int)half_width);
            SolidBrush mybrush = new SolidBrush(Color.White);
            Pen mypen = new Pen(Color.Brown);

            //在RBF演算法下作調整
            for (int i = 0; i < iter; i++)
            {
                for (int j = 0; j < dataset.Count; j++)
                {
                    double middle=0;
                    for (int k = 0; k < neuron.Length; k++)
                    {
                        double nn1 = neuron[k].basis_function(dataset[j]);
                        middle += neuron[k].weight * nn1;
                    }
                    middle += threshold;
                    Fx = middle;

                    for (int m = 0; m < neuron.Length; m++)
                    {
                        double mm1 = 0;
                        double mm2 = 0;
                        double nn2 = 0;

                        //調整每個神經元的鍵結值
                        nn2 = neuron[m].basis_function(dataset[j]);
                        neuron[m].weight += learning_rate * (dataset[j][2] - Fx) * nn2;
                        neuron[m].weight = Math.Round(neuron[m].weight,3);

                        //調整每個神經元的標準差
                        for (int mj = 0; mj < neuron[m].ANNmean.Length; mj++)
                            mm1 += Math.Pow(dataset[j][mj] - neuron[m].ANNmean[mj], 2);
                        neuron[m].sigma -= learning_rate * (dataset[j][2] - Fx) * neuron[m].weight * nn2*mm1/Math.Pow(neuron[m].sigma,3);
                        neuron[m].sigma = Math.Round(neuron[m].sigma, 5);

                        //調整每個神經元的平均值
                        for (int mn = 0; mn < neuron[m].ANNmean.Length; mn++)
                        {
                            mm2 = dataset[j][mn] - neuron[m].ANNmean[mn];
                            neuron[m].ANNmean[mn] += learning_rate * (dataset[j][2] - Fx) * neuron[m].weight * nn2 * mm2
                                / Math.Pow(neuron[m].sigma, 2);
                            neuron[m].ANNmean[mn] = Math.Round(neuron[m].ANNmean[mn], 2);
                        }
                    }

                    //調整閥值
                    threshold += learning_rate * (dataset[j][2] - Fx);
                    threshold = Math.Round(threshold,3);
                }

            }

            textBox5.Text += " 迭代後的平均值 " + Environment.NewLine;
            textBox6.Text += " 迭代後的鍵結值 " + Environment.NewLine;
            textBox7.Text += " 迭代後的標準差 " + Environment.NewLine;
            for (int i = 0; i < neuron.Length; i++)
            {
                textBox5.Text += neuron[i].ANNmean[0] + " , " + neuron[i].ANNmean[1] + Environment.NewLine;
                textBox6.Text += neuron[i].weight + Environment.NewLine;
                textBox7.Text += neuron[i].sigma + Environment.NewLine;
            }
            textBox8.Text += " 迭代後的閥值 " + Environment.NewLine + threshold;

            //畫圖
            double[] radius = new double[neuronNUM];//神經元初始半徑
            Unit = max_dis / half_height;
            int count = 0; //紀錄用到的半徑

            foreach (var data in neuron)
            {
                radius[count] = Math.Ceiling(data.sigma / Unit);
                Rectangle dot = new Rectangle((int)(half_height * data.ANNmean[0] / max_dis), (int)(-1 * half_width * data.ANNmean[1] / max_dis), 3, 3);
                graph.FillEllipse(mybrush, dot);

                graph.DrawEllipse(mypen, (int)(half_height * data.ANNmean[0] / max_dis) - (int)(radius[count] / 2),
                    (int)(-1 * half_width * data.ANNmean[1] / max_dis) - (int)(radius[count] / 2),
                    (int)radius[count], (int)radius[count]);
                count++;
            }
            pictureBox1.Image = windowRBF;
            graph.Dispose();
        }
			packet = new Packet(element) {

				@Override
Esempio n. 38
0
        private static void SortByFreqInefficient(int[] arr)
        {
            int[] op = new int[arr.Length];
            Dictionary<int, element> dict = new Dictionary<int, element>();
            List<element> lstEle = new List<element>();
            for (int i = 0; i < arr.Length; i++)
            {
                if (!dict.ContainsKey(arr[i]))
                {
                    element e = new element(arr[i], i);
                    dict.Add(arr[i], e);
                    lstEle.Add(e);
                    heapify(lstEle);
                }
                else
                {
                    dict[arr[i]].freq++;
                    siftDown(lstEle, 0, lstEle.Count - 1);
                }

                op[i] = lstEle[0].val;
            }

            for (int i = 0; i < op.Length; i++)
            {
                Console.WriteLine("arr[{0}] = {1}", i, op[i]);
            }
        }
        // quadratic spline interpolation
        public double[][] quadSpline(Point[] coords)
        {
            int polyType = 2;
            int n = coords.Length-1; //number of intervals (n+1 points, n intervals)
            double[][] matrix = new double[(3*n)-1][]; //minus 1 since a1 = 0
            double[][] finalMatrix = new double[(3 * n) - 1][];
            //so we need to generate 3n equations
            int pow;
            element[][] dummy = new element[(3 * n) - 1][];
            for (int x = 0; x < (3 * n - 1); x++)
            {
                matrix[x] = new double[(3 * n)+1];
                finalMatrix[x] = new double[(3 * n)];
                dummy[x] = new element[polyType + 2];
            }

            for (int i = 0,counter=0,index=2 ; index < coords.Length; i+=2, index++,counter += 3)
            {
                for(int j =0 ; j < polyType+2 ; j++)
                {
                    pow = polyType - j;
                    if (pow < 0)
                        pow = 0;
                    if (j >= polyType + 1)
                    {
                        dummy[i][j].value = coords[index-1].Y;
                        dummy[i][j].column = 3*n;

                        dummy[i+1][j].value = coords[index-1].Y;
                        dummy[i + 1][j].column = 3 * n;
                    }
                    else
                    {
                        dummy[i][j].value = Math.Pow(coords[index-1].X, pow);
                        dummy[i][j].column = j + counter;

                        dummy[i+1][j].value = Math.Pow(coords[index-1].X, pow);
                        dummy[i+1][j].column = j + counter + 3;
                    }

                }
               // textBox3.AppendText("\n");
            }

            for (int j = 0 ; j < polyType + 2; j++)
            {
                pow = polyType - j;
                if (j >= polyType + 1)
                {
                    dummy[2*n-2][j].value = coords[0].Y;
                    dummy[2 * n - 2][j].column = 3 * n;

                    dummy[2 * n - 1][j].value = coords[n].Y;
                    dummy[2 * n - 1][j].column = 3 * n;
                }
                else
                {
                    dummy[2 * n - 2][j].value = Math.Pow(coords[0].X, pow);
                    dummy[2 * n - 2][j].column = j;

                    dummy[2 * n - 1][j].value = Math.Pow(coords[n].X, pow);
                    dummy[2 * n - 1][j].column = (3 * n) - n + j;
                }
            }

            for (int i = 2*n, counter = 0,index=2; i < (3*n-1); i++, counter += 3,index++)
            {
                //dummy[i] = new element[polyType+2];
                if (index == coords.Length)
                {
                    index = 2;
                    counter = 0;
                }

                dummy[i][0].value = 2 * coords[index - 1].X;
                dummy[i][0].column = 0 + counter;

                dummy[i][1].value = 1;
                dummy[i][1].column = 1 + counter;

                dummy[i][2].value = 2 * -coords[index - 1].X;
                dummy[i][2].column = 0 + counter+3;

                dummy[i][3].value = -1;
                dummy[i][3].column = 1 + counter+3;

            }

            for (int i = 0; i < 3*n-1; i++)
            {
                for (int j = 0; j < polyType+2; j++)
                {
                    matrix[i][dummy[i][j].column] = dummy[i][j].value;
                }
            }

            for (int i = 0; i < 3 * n - 1; i++)
            {
                for (int j = 0; j < 3 * n; j++)
                {
                    finalMatrix[i][j] = matrix[i][j+1];
                }
            }
            /*
            for (int k = 0; k < (3 * n - 1); k++)
            {
                for (int l = 0; l < (3 * n); l++)
                //for (int l = 0; l < polyType + 2; l++)
                {
                    //textBox3.AppendText(dummy[k][l].column.ToString() + "  ");
                    textBox3.AppendText(finalMatrix[k][l].ToString() + "  ");
                }
                textBox3.AppendText("\n");
            }
             */
            return finalMatrix;
        }