コード例 #1
0
        public static void DFS_for_WD(Working_data wd)
        {
            for (int i = 0; i < (wd.info.information as External_module.Operators).if_Operators.Count; i++)
            {
                bool isCorrect = false;
                for (int k = 0; k < ifs.Count; k++)
                {
                    if ((wd.info.information as External_module.Operators).if_Operators[i] == ifs[k].info.information)
                    {
                        if (ifs[k].path == -1)
                        {
                            DFS_for_if(ifs[k]);
                        }
                        if (ifs[k].path >= 0)
                        {
                            for (int q = 0; q < (wd.info.information as External_module.Operators).if_Operators[i].exits[ifs[k].path].Count; q++)
                            {
                                if ((wd.info.information as External_module.Operators).if_Operators[i].exits[ifs[k].path][q] == Controller.results[i].information)
                                {
                                    isCorrect = true;
                                    break;
                                }
                            }
                        }
                        else
                        {
                            isCorrect = true;
                        }
                        break;
                    }
                }
                if (!isCorrect)
                {
                    wd.isTrue = false;
                    return;
                }
            }
            List <int> indexes = new List <int>();
            Operators  w       = wd.info.information as Operators;

            if (w.Count_of_up_connection != -1 && w.up_Conection.Count != w.Count_of_up_connection)
            {
                wd.isTrue = false;
                return;
            }
            else
            {
                for (int i = 0; i < w.up_Conection.Count; i++)
                {
                    for (int j = 0; j < Data.Count; j++)
                    {
                        if (Data[j].info.information == w.up_Conection[i])
                        {
                            indexes.Add(j);
                            if (Data[j].data == null)
                            {
                                DFS_for_WD(Data[j]);
                                if (Data[j].data == null)
                                {
                                    Data[j].isTrue = false;
                                }
                            }
                            if (!Data[j].isTrue && w.Count_of_up_connection != -1)
                            {
                                wd.isTrue = false;
                                return;
                            }
                            break;
                        }
                    }
                }
                if (w.Count_of_up_connection == 1)
                {
                    wd.data = Config.operands(wd.info.information.name, new Math_Field[] { Data[indexes[0]].data });
                }
                else
                {
                    if (w.Count_of_up_connection == 2)
                    {
                        if (Math_Field.idCOM(Data[indexes[0]].data, Data[indexes[1]].data))
                        {
                            Math_Field.id_to_normal(Data[indexes[0]].data, ref Data[indexes[1]].data);
                        }
                        else
                        {
                            Math_Field.id_to_normal(Data[indexes[1]].data, ref Data[indexes[0]].data);
                        }
                        wd.data = Config.operands(wd.info.information.name, new Math_Field[] { Data[indexes[0]].data, Data[indexes[1]].data });
                    }
                    else
                    {
                        int fall = -1;
                        for (int i = 0; i < indexes.Count; i++)
                        {
                            if (Data[indexes[i]].isTrue)
                            {
                                fall = i;
                                break;
                            }
                        }
                        if (fall != -1)
                        {
                            wd.data = Data[indexes[fall]].data;
                            Math_Field[] opearnds = new Math_Field[indexes.Count];
                            int          Count    = 0;
                            for (int i = fall + 1; i < indexes.Count; i++)
                            {
                                if (Data[indexes[i]].isTrue)
                                {
                                    if (Math_Field.idCOM(wd.data, Data[indexes[i]].data))
                                    {
                                        Math_Field.id_to_normal(wd.data, ref Data[indexes[i]].data);
                                    }
                                    else
                                    {
                                        Math_Field.id_to_normal(Data[indexes[i]].data, ref wd.data);
                                    }
                                    opearnds[Count] = Data[indexes[i]].data;
                                    Count++;
                                }
                            }
                            Array.Resize(ref opearnds, Count + 1);
                            wd.data = Config.operands(wd.info.information.name, opearnds);
                        }
                        else
                        {
                            wd.isTrue = false;
                            return;
                        }
                    }
                }
                if (check)
                {
                    while (wd.data.isDown)
                    {
                        wd.data = wd.data.Dawn();
                    }
                }
            }
        }
コード例 #2
0
        public static void DFS_for_WD(Working_data wd)
        {
            for (int i = 0; i < (wd.info.information as External_module.Operators).if_Operators.Count; i++)
            {
                bool isCorrect = false;
                for (int k = 0; k < ifs.Count; k++)
                {
                    if ((wd.info.information as External_module.Operators).if_Operators[i] == ifs[k].info.information)
                    {
                        if (ifs[k].path == -1)
                        {
                            DFS_for_if(ifs[k]);
                        }
                        if (ifs[k].path >= 0)
                        {
                            for (int q = 0; q < (wd.info.information as External_module.Operators).if_Operators[i].exits[ifs[k].path].Count; q++)
                            {
                                if ((wd.info.information as External_module.Operators).if_Operators[i].exits[ifs[k].path][q] == Controller.results[i].information)
                                {
                                    isCorrect = true;
                                    break;
                                }
                            }
                        }
                        else
                        {
                            isCorrect = true;
                        }
                        break;
                    }
                }
                if (!isCorrect)
                {
                    wd.isTrue = false;
                    return;
                }
            }
            List <int> indexes = new List <int>();
            Operators  w       = wd.info.information as Operators;

            if (w.Count_of_up_connection != -1 && w.up_Conection.Count != w.Count_of_up_connection)
            {
                wd.isTrue = false;
                return;
            }
            else
            {
                for (int i = 0; i < w.up_Conection.Count; i++)
                {
                    for (int j = 0; j < Data.Count; j++)
                    {
                        if (Data[j].info.information == w.up_Conection[i])
                        {
                            indexes.Add(j);
                            if (Data[j].data == null)
                            {
                                DFS_for_WD(Data[j]);
                                if (Data[j].data == null)
                                {
                                    Data[j].isTrue = false;
                                }
                            }
                            if (!Data[j].isTrue && w.Count_of_up_connection != -1)
                            {
                                wd.isTrue = false;
                                return;
                            }
                            break;
                        }
                    }
                }
                if (w.Count_of_up_connection == 1)
                {
                    switch (wd.info.information.name)
                    {
                    case "ABS":
                    {
                        wd.data = Data[indexes[0]].data.ABS;
                    }
                    break;

                    case "(-1)":
                    {
                        wd.data = Data[indexes[0]].data.UNT;
                    }
                    break;

                    case "DIF":
                    {
                        wd.data = Data[indexes[0]].data.DER;
                    }
                    break;

                    case "LED":
                    {
                        wd.data = Data[indexes[0]].data.LED;
                    }
                    break;

                    case "deg":
                    {
                        wd.data = Data[indexes[0]].data.DEG;
                    }
                    break;

                    case "Down":
                    {
                        wd.data = Data[indexes[0]].data.Dawn();
                    }
                    break;

                    case "up":
                    {
                        wd.data = Data[indexes[0]].data.External_Up();
                    }
                    break;

                    default:
                    {
                        wd.isTrue = false;
                    }
                    break;
                    }
                }
                else
                {
                    if (w.Count_of_up_connection == 2)
                    {
                        if (Math_Field.idCOM(Data[indexes[0]].data, Data[indexes[1]].data))
                        {
                            Math_Field.id_to_normal(Data[indexes[0]].data, ref Data[indexes[1]].data);
                        }
                        else
                        {
                            Math_Field.id_to_normal(Data[indexes[1]].data, ref Data[indexes[0]].data);
                        }
                        switch (wd.info.information.name)
                        {
                        case "-":
                        {
                            wd.data = Data[indexes[0]].data.SUB(Data[indexes[1]].data);
                        }
                        break;

                        case "/":
                        {
                            wd.data = Data[indexes[0]].data.DIV(Data[indexes[1]].data);
                        }
                        break;

                        case "%":
                        {
                            wd.data = Data[indexes[0]].data.MOD(Data[indexes[1]].data);
                        }
                        break;
                        }
                    }
                    else
                    {
                        int fall = -1;
                        for (int i = 0; i < indexes.Count; i++)
                        {
                            if (Data[indexes[i]].isTrue)
                            {
                                fall = i;
                                break;
                            }
                        }
                        if (fall != -1)
                        {
                            wd.data = Data[indexes[fall]].data;
                            for (int i = fall + 1; i < indexes.Count; i++)
                            {
                                if (Data[indexes[i]].isTrue)
                                {
                                    if (Math_Field.idCOM(wd.data, Data[indexes[i]].data))
                                    {
                                        Math_Field.id_to_normal(wd.data, ref Data[indexes[i]].data);
                                    }
                                    else
                                    {
                                        Math_Field.id_to_normal(Data[indexes[i]].data, ref wd.data);
                                    }
                                    switch (wd.info.information.name)
                                    {
                                    case "+":
                                    {
                                        wd.data = wd.data.ADD(Data[indexes[i]].data);
                                    }
                                    break;

                                    case "*":
                                    {
                                        wd.data = wd.data.MUL(Data[indexes[i]].data);
                                    }
                                    break;

                                    case "НОД":
                                    {
                                        wd.data = wd.data.GCF(Data[indexes[i]].data);
                                    }
                                    break;

                                    case "НОК":
                                    {
                                        wd.data = wd.data.LCM(Data[indexes[i]].data);
                                    }
                                    break;
                                    }
                                }
                            }
                        }
                        else
                        {
                            wd.isTrue = false;
                            return;
                        }
                    }
                }
                if (check)
                {
                    while (wd.data.isDown)
                    {
                        wd.data = wd.data.Dawn();
                    }
                }
            }
        }
コード例 #3
0
 public static void DFS_for_if(if_operator if_)
 {
     for (int i = 0; i < if_.info.information.if_Operators.Count; i++)
     {
         bool isCorrect = false;
         for (int k = 0; k < ifs.Count; k++)
         {
             if (if_.info.information.if_Operators[i] == ifs[k].info.information)
             {
                 if (ifs[k].path == -1)
                 {
                     DFS_for_if(ifs[k]);
                 }
                 if (ifs[k].path >= 0)
                 {
                     for (int q = 0; q < if_.info.information.if_Operators[i].exits[ifs[k].path].Count; q++)
                     {
                         if (if_.info.information.if_Operators[i].exits[ifs[k].path][q] == Controller.results[i].information)
                         {
                             isCorrect = true;
                             break;
                         }
                     }
                 }
                 else
                 {
                     isCorrect = true;
                 }
                 break;
             }
         }
         if (!isCorrect)
         {
             if_.path = -2;
             return;
         }
     }
     try
     {
         List <int> indexes = new List <int>();
         for (int k = 0; k < if_.info.information.up_connection.Count; k++)
         {
             for (int j = 0; j < Data.Count; j++)
             {
                 if (if_.info.information.up_connection[k] == Data[j].info.information)
                 {
                     indexes.Add(j);
                     if (Data[j].data == null)
                     {
                         DFS_for_WD(Data[j]);
                         if (Data[j].data == null)
                         {
                             Data[j].isTrue = false;
                         }
                     }
                     if (!Data[j].isTrue)
                     {
                         throw new Exception();
                     }
                     break;
                 }
             }
         }
         Math_Field[] opearnds = new Math_Field[indexes.Count];
         int          Count    = 0;
         for (int i = 0; i < indexes.Count; i++)
         {
             if (Data[indexes[i]].isTrue)
             {
                 if (Math_Field.idCOM(Data[indexes[0]].data, Data[indexes[i]].data))
                 {
                     Math_Field.id_to_normal(Data[indexes[0]].data, ref Data[indexes[i]].data);
                 }
                 else
                 {
                     Math_Field.id_to_normal(Data[indexes[i]].data, ref Data[indexes[0]].data);
                 }
                 opearnds[Count] = Data[indexes[i]].data;
                 Count++;
             }
         }
         if_.path = Config.logic(if_.info.information.name, opearnds);
     }
     catch
     {
         if_.path = -1;
         return;
     }
 }
コード例 #4
0
        public static void DFS_for_if(if_operator if_)
        {
            for (int i = 0; i < if_.info.information.if_Operators.Count; i++)
            {
                bool isCorrect = false;
                for (int k = 0; k < ifs.Count; k++)
                {
                    if (if_.info.information.if_Operators[i] == ifs[k].info.information)
                    {
                        if (ifs[k].path == -1)
                        {
                            DFS_for_if(ifs[k]);
                        }
                        if (ifs[k].path >= 0)
                        {
                            for (int q = 0; q < if_.info.information.if_Operators[i].exits[ifs[k].path].Count; q++)
                            {
                                if (if_.info.information.if_Operators[i].exits[ifs[k].path][q] == Controller.results[i].information)
                                {
                                    isCorrect = true;
                                    break;
                                }
                            }
                        }
                        else
                        {
                            isCorrect = true;
                        }
                        break;
                    }
                }
                if (!isCorrect)
                {
                    if_.path = -2;
                    return;
                }
            }
            try
            {
                List <int> indexes = new List <int>();
                for (int k = 0; k < if_.info.information.up_connection.Count; k++)
                {
                    for (int j = 0; j < Data.Count; j++)
                    {
                        if (if_.info.information.up_connection[k] == Data[j].info.information)
                        {
                            indexes.Add(j);
                            if (Data[j].data == null)
                            {
                                DFS_for_WD(Data[j]);
                                if (Data[j].data == null)
                                {
                                    Data[j].isTrue = false;
                                }
                            }
                            if (!Data[j].isTrue)
                            {
                                throw new Exception();
                            }
                            break;
                        }
                    }
                }
                switch (if_.info.information.name)
                {
                case "COM_NN_D":
                {
                    if (Math_Field.idCOM(Data[indexes[0]].data, Data[indexes[1]].data))
                    {
                        Math_Field.id_to_normal(Data[indexes[0]].data, ref Data[indexes[1]].data);
                        switch (Data[indexes[0]].data.COM(Data[indexes[1]].data))
                        {
                        case 1:
                        {
                            if_.path = 0;
                        }
                        break;

                        case 0:
                        {
                            if_.path = 1;
                        }
                        break;

                        case 2:
                        {
                            if_.path = 2;
                        }
                        break;
                        }
                    }
                    else
                    {
                        Math_Field.id_to_normal(Data[indexes[1]].data, ref Data[indexes[0]].data);
                        switch (Data[indexes[1]].data.COM(Data[indexes[0]].data))
                        {
                        case 2:
                        {
                            if_.path = 0;
                        }
                        break;

                        case 0:
                        {
                            if_.path = 1;
                        }
                        break;

                        case 1:
                        {
                            if_.path = 2;
                        }
                        break;
                        }
                    }
                    return;
                }

                case "isDown":
                {
                    if (Data[indexes[0]].data.isDown)
                    {
                        if_.path = 0;
                    }
                    else
                    {
                        if_.path = 1;
                    }
                    return;
                }
                }
            }
            catch
            {
                if_.path = -1;
                return;
            }
        }