コード例 #1
0
        private void ApplyInputOperations(LogicalElement logicalTree, List <QueryPlanNode> path)
        {
            if (logicalTree == null)
            {
                return;
            }

            PhysicalOperation curNode   = path.First(x => x.LogicalElement == logicalTree).PhysicalOperation;
            PhysicalOperation leftInput = null;

            if (logicalTree.LeftChild != null)
            {
                leftInput = path.First(x => x.LogicalElement == logicalTree.LeftChild).PhysicalOperation;
            }

            PhysicalOperation rightInput = null;

            if (logicalTree.RightChild != null)
            {
                rightInput = path.First(x => x.LogicalElement == logicalTree.RightChild).PhysicalOperation;
            }

            curNode?.SetInput(leftInput, rightInput);

            ApplyInputOperations(logicalTree.LeftChild, path);
            ApplyInputOperations(logicalTree.RightChild, path);
        }
コード例 #2
0
 public IndexSeekOperation(LogicalElement logicalElement, Table table, IBPlusTreeNode index, Condition condition)
     : base(logicalElement)
 {
     Table     = table;
     Condition = condition;
     _index    = index;
 }
コード例 #3
0
    public void Save()
    {
        List <SElement> elements = new List <SElement>();

        for (int i = 0; i < elements_parent.childCount; i++)
        {
            var ce = elements_parent.GetChild(i).GetComponent <CircuitElement>();
            //Debug.Log(ce);
            string type = ce is EditableOut ? "editableout" :
                          ce is OrLogicalElement ? "or" :
                          ce is AND ? "and" :
                          ce is NotLogicalElement ? "not" :
                          ce is ButtonLogicalElement ? "button" :
                          ce is BitDisplay ? "bitdisplay" :
                          ce is SplitterLogicalElement ? "splitter" :
                          ce is NandLogicalElement ? "nand" :
                          ce is RepeaterLogicalElement ? "repeater" :
                          ce is EqualLogicalElement ? "equal" :
                          ce is XorLogicalElement ? "xor" :
                          ce is NorLogicalElement ? "nor" :

                          "error";
            SElement se = new SElement(type, ce.transform.position, i);
            elements.Add(se);
        }
        for (int i = 0; i < elements.Count; i++)
        {
            var ce = elements_parent.GetChild(i).GetComponent <CircuitElement>();

            LogicalElement le = ce as LogicalElement;

            for (int out_id = 0; out_id < le.outPoints.Length; out_id++)
            {
                if (le.outPoints[out_id].Out != null)
                {
                    elements[i].out_ids.Add(new EndNode(le.outPoints[out_id].Out.transform.parent.GetSiblingIndex(), le.outPoints[out_id].Out.transform.GetSiblingIndex()));
                }
                else
                {
                    elements[i].out_ids.Add(new EndNode());
                }
            }
        }
        var             file_name = Path.Combine(Application.persistentDataPath, "circuit.dat");
        FileStream      fs        = new FileStream(file_name, FileMode.Create);
        BinaryFormatter formatter = new BinaryFormatter();

        try
        {
            formatter.Serialize(fs, elements);
        }
        catch (SerializationException e)
        {
            throw new ArgumentException("Failed to serialize " + file_name, e.Message);
        }
        finally
        {
            fs.Close();
        }
    }
コード例 #4
0
        //private PhysicalOperation FindIndexes(SelectionElement selectionElement)
        //{
        //    List<LeafCondition> leafs = GetLeafConditions(selectionElement.Condition);

        //    foreach(LeafCondition leaf in leafs)
        //    {
        //        if (leaf.Column.Relation is TableDefinition tableDefinition)
        //        {
        //            Index index = tableDefinition.Indexes.FirstOrDefault(x => string.Equals(x.Column, leaf.Column.Name, StringComparison.OrdinalIgnoreCase));

        //            if (index != null)
        //            {
        //                ;
        //            }
        //        }
        //    }

        //    if (leafs.Count == 0)
        //    {
        //        // index seek / table scan
        //        return GetFullTableScanOperation(selectionElement..)
        //    }
        //}

        public PhysicalOperation GetPhysicalPlan(LogicalElement logicalTree)
        {
            List <LogicalElement> postorderLogicalTree = AppendPostOrder(new List <LogicalElement>(), logicalTree);

            QueryPlanNode root = new QueryPlanNode(null, null);

            List <QueryPlanNode> lastOptions = new List <QueryPlanNode> {
                root
            };

            for (int i = 0; i < postorderLogicalTree.Count; i++)
            {
                LogicalElement element = postorderLogicalTree[i];

                Dictionary <QueryPlanNode, int> options = GetOptions(element);
                ConnectEndNodesToNodes(lastOptions, options);

                lastOptions = options.Select(x => x.Key).ToList();
            }

            List <QueryPlanNode> leastCostPath = GetLeastCostPath(root);

            PhysicalOperation physicalOperation = CreateFromPath(logicalTree, leastCostPath);

            return(physicalOperation);
        }
コード例 #5
0
 public NestedLoopJoinOperation(LogicalElement logicalElement, ReadLogicalElement left, ReadLogicalElement right, AttributeDefinition leftJoinColumn, AttributeDefinition rightJoinColumn)
     : base(logicalElement)
 {
     LeftLogical      = left;
     RightLogical     = right;
     _leftJoinColumn  = leftJoinColumn;
     _rightJoinColumn = rightJoinColumn;
 }
コード例 #6
0
    void OnInspectorGUI()
    {
        LogicalElement script = (LogicalElement)target;
        Object         obj    = EditorGUILayout.ObjectField("Light", (Object)script.inputElement, typeof(IOneOutput), true);

        //script.inputElement = obj as IOneOutput;
        DrawDefaultInspector();
    }
コード例 #7
0
 public HashSetJoinOperation(LogicalElement logicalElement, PhysicalOperation left, PhysicalOperation right, AttributeDefinition leftJoinColumn, AttributeDefinition rightJoinColumn)
     : base(logicalElement)
 {
     Left             = left;
     Right            = right;
     _leftJoinColumn  = leftJoinColumn;
     _rightJoinColumn = rightJoinColumn;
 }
コード例 #8
0
        private List <LogicalElement> AppendPostOrder(List <LogicalElement> result, LogicalElement center)
        {
            if (center.LeftChild != null)
            {
                AppendPostOrder(result, center.LeftChild);
            }
            if (center.RightChild != null)
            {
                AppendPostOrder(result, center.RightChild);
            }
            result.Add(center);

            return(result);
        }
コード例 #9
0
 void Start()
 {
     //находим свечение логического элемента
     light = new List <GameObject>();
     for (int i = 0; i < transform.childCount; i++)
     {
         child = transform.GetChild(i).gameObject;
         if (child.CompareTag("Light"))
         {
             light.Add(child);
         }
     }
     element = GetComponent <LogicalElement>();
 }
コード例 #10
0
    //функция движения поршня
    void PistonAction(LogicalElement A)
    {
        state       = A.state;
        isConnected = Physics2D.Raycast(rayStart, pistonDirection, 5f * transform.localScale.x, m);

        //движение происходит только если объект связан с поршнем
        if (isConnected)
        {
            if (state)
            {
                if (isNotPlaying)
                {
                    ssPiston.MakeSound();
                    isNotPlaying = false;
                }
                //отталкивание объекта
                startPos           = pulledObject.transform.position;
                endPos             = pulledObjPos + pistonDirection * pushDistance;
                pistonHeadStartPos = pistonHead.position;
                pistonHeadEndPos   = pistonHeadPos + pistonDirection * pushDistance;

                PistonMovementCalculaton(startPos, endPos, pistonHeadStartPos, pistonHeadEndPos);
                PistonSoundStop(endPos);
            }
            else
            {
                if (isNotPlaying)
                {
                    ssPiston.MakeSound();
                    isNotPlaying = false;
                }
                //притягивание объекта
                startPos           = pulledObject.transform.position;
                endPos             = pulledObjPos;
                pistonHeadStartPos = pistonHead.position;
                pistonHeadEndPos   = pistonHeadPos;

                PistonMovementCalculaton(startPos, endPos, pistonHeadStartPos, pistonHeadEndPos);
                PistonSoundStop(endPos);
            }
        }
    }
コード例 #11
0
    void Awake()
    {
        /*
         * У каждого провода есть определенный тэг,
         * по которому они и находятся в этой строчке,
         * и добавляются в массив с проводами.
         */
        wires = GameObject.FindGameObjectsWithTag("Wire");

        /*
         * В этом цикле мы проходим по всем проводам, и смотрим, если они приклеплены к одному элементу,
         * то скрипт назначает им точки входа.
         */
        for (var i = 0; i < wires.Length - 1; i++)
        {
            for (var j = i + 1; j < wires.Length; j++)
            {
                //Берем сам элемент, к которому приклеплен провод
                leI = wires[i].GetComponent <LogicalWire>().GetLe2;
                leJ = wires[j].GetComponent <LogicalWire>().GetLe2;
                if (leI == leJ)
                {
                    wires[j].GetComponent <LogicalWire>().SetOutp = leJ.gameObject.transform.Find("inPoint 2");
                    wires[i].GetComponent <LogicalWire>().SetOutp = leI.gameObject.transform.Find("inPoint 1");
                }

                if (leJ is LogicalNot || leJ is LogicalPiston)
                {
                    wires[j].GetComponent <LogicalWire>().SetOutp = leJ.gameObject.transform.Find("inPoint 1");
                }
            }
            if (leI is LogicalNot || leI is LogicalPiston)
            {
                wires[i].GetComponent <LogicalWire>().SetOutp = leI.gameObject.transform.Find("inPoint 1");
            }
        }
    }
コード例 #12
0
 // probably should not have data in the queryplan itself
 public MemorySetOperation(LogicalElement logicalElement, Set set)
     : base(logicalElement)
 {
     Set = set.ToList();
 }
コード例 #13
0
 public TableScanOperation(LogicalElement logicalElement, Table table)
     : base(logicalElement)
 {
     Table = table;
 }
コード例 #14
0
 public UnionOperator(LogicalElement logicalElement, PhysicalOperation left, PhysicalOperation right)
     : base(logicalElement)
 {
     Left  = left;
     Right = right;
 }
コード例 #15
0
 public InsertOperation(LogicalElement logicalElement, Table table)
     : base(logicalElement)
 {
     Table = table;
 }
コード例 #16
0
 internal LogicalElementProxy(LogicalElement le)
 {
     this.le = le;
 }
コード例 #17
0
 /*
  * Логическое И принимает на вход один сигнал и выдает положительное состояние,
  * если состояние на входе отрицательное, инвертируя сигнал.
  */
 public void Logical_not(LogicalElement A)
 {
     state = !A.state;
 }
コード例 #18
0
        public static List <CustomTuple> ExecuteQuery(string query, bool debug = false)
        {
            if (LogicalQueryPlan == null)
            {
                LogicalQueryPlan = new LogicalQueryPlan(RelationManager);
            }
            if (PhysicalQueryPlan == null)
            {
                PhysicalQueryPlan = new PhysicalQueryPlan(RelationManager, StatisticsManager);
            }

            if (Program.Debug)
            {
                Console.WriteLine("[DEBUG]: Query: " + query);
            }
            LogicalElement logicalTree = LogicalQueryPlan.GetTreeForQuery(query);

            List <CustomTuple> results = new List <CustomTuple>();

            if (logicalTree == null)
            {
                return(results);
            }

            PhysicalOperation physicalOperation = PhysicalQueryPlan.GetPhysicalPlan(logicalTree);

            if (query == UserQuery)
            {
                ;
            }

            if (debug)
            {
                //string s = element.ToDot();
                //;
            }

            physicalOperation.Prepare();


            CustomTuple result;

            do
            {
                result = physicalOperation.GetNext();

                if (result != null)
                {
                    results.Add(result);
                }
            }while (result != null);

            //QueryPlan plan = new QueryPlan(command);

            //int reads = MemoryBuffer.Reads;
            //int writes = MemoryManager.Writes;
            //List<CustomTuple> result = plan.Execute();
            //if (Program.Debug)
            //{
            //    Console.WriteLine("[DEBUG]: Reads for last query: " + (MemoryBuffer.Reads - reads) + " (total: " + reads + "), writes: " + (MemoryManager.Writes - writes) + " (total: " + writes + ")");
            //}

            return(results);
        }
コード例 #19
0
 public IndexScanOperation(LogicalElement logicalElement, Table table, IBPlusTreeNode index)
     : base(logicalElement)
 {
     Table  = table;
     _index = index;
 }
コード例 #20
0
 public void CircuitChanged()
 {
     element = GetComponentInParent <LogicalElement>();
     element.CircuitChanged();
 }
コード例 #21
0
 public QueryPlanNode(LogicalElement logicalElement, PhysicalOperation physicalOperation)
 {
     LogicalElement    = logicalElement;
     PhysicalOperation = physicalOperation;
     Id = MaxId++;
 }
コード例 #22
0
        internal PhysicalOperation CreateFromPath(LogicalElement logicalTree, List <QueryPlanNode> path)
        {
            ApplyInputOperations(logicalTree, path);

            return(path.First(x => x.LogicalElement == logicalTree).PhysicalOperation);
        }
コード例 #23
0
        private Dictionary <QueryPlanNode, int> GetOptions(LogicalElement element)
        {
            Dictionary <QueryPlanNode, int> options = new Dictionary <QueryPlanNode, int>();

            if (element is ProjectionElement p)
            {
                PhysicalOperation proj = new ProjectionOperation(element, null, p.Columns.Select(x => x.AttributeDefinition).ToList());
                options.Add(new QueryPlanNode(element, proj), proj.GetCost());
            }
            else if (element is SelectionElement selectionElement)
            {
                if (selectionElement.LeftChild is RelationElement relationElement)
                {
                    Table table = Program.RelationManager.GetTable(relationElement.Relation.Id);

                    PhysicalOperation tableScan = new TableScanOperation(element, table);
                    if (selectionElement.Condition != null)
                    {
                        PhysicalOperation f = new FilterOperation(element, tableScan, selectionElement.Condition);
                        options.Add(new QueryPlanNode(element, f), f.GetCost());
                    }
                    else
                    {
                        options.Add(new QueryPlanNode(element, tableScan), tableScan.GetCost());
                    }

                    Condition clonedCondition = selectionElement.Condition?.Clone();

                    if (TryExtractConstantConditionWithIndex(relationElement.Relation, clonedCondition, out LeafCondition constantCondition))
                    {
                        selectionElement.Condition = selectionElement.Condition.Simplify();

                        PhysicalOperation indexSeek = new IndexSeekOperation(element, table, table.GetIndex(table.TableDefinition.GetClusteredIndex().Column), constantCondition);

                        if (selectionElement.Condition != null)
                        {
                            PhysicalOperation f = new FilterOperation(element, indexSeek, clonedCondition);
                            options.Add(new QueryPlanNode(element, f), f.GetCost());
                        }
                        else
                        {
                            options.Add(new QueryPlanNode(element, indexSeek), indexSeek.GetCost());
                        }
                    }
                    else
                    {
                        if (table.TableDefinition.HasClusteredIndex())
                        {
                            PhysicalOperation indexSeek = new IndexSeekOperation(element, table, table.GetIndex(table.TableDefinition.GetClusteredIndex().Column), constantCondition);

                            if (selectionElement.Condition != null)
                            {
                                PhysicalOperation f = new FilterOperation(element, indexSeek, selectionElement.Condition);
                                options.Add(new QueryPlanNode(element, f), f.GetCost());
                            }
                            else
                            {
                                options.Add(new QueryPlanNode(element, indexSeek), indexSeek.GetCost());
                            }
                        }
                    }
                }
            }
            else if (element is RelationElement relElement)
            {
                Table table = Program.RelationManager.GetTable(relElement.Relation.Id);

                if (table.TableDefinition.HasClusteredIndex())
                {
                    PhysicalOperation indexSeek = new IndexScanOperation(element, table, table.GetIndex(table.TableDefinition.GetClusteredIndex().Column));
                    options.Add(new QueryPlanNode(element, indexSeek), indexSeek.GetCost());
                }

                PhysicalOperation tableScan = new TableScanOperation(element, table);
                options.Add(new QueryPlanNode(element, tableScan), tableScan.GetCost());
            }
            else if (element is CartesianProductElement cartesianProduct)
            {
                PhysicalOperation left  = null; //GetDefaultPhysicalOperation(element.LeftChild);
                PhysicalOperation right = null; //GetDefaultPhysicalOperation(element.RightChild);

                PhysicalOperation join = new NestedLoopJoinOperation(cartesianProduct, (ReadLogicalElement)element.LeftChild, (ReadLogicalElement)element.RightChild, cartesianProduct.LeftJoinColumn, cartesianProduct.RightJoinColumn);
                options.Add(new QueryPlanNode(cartesianProduct, join), join.GetCost());
            }
            else if (element is MemorySetElement memElem)
            {
                options.Add(new QueryPlanNode(memElem, new MemorySetOperation(memElem, memElem.Set)), 0);
            }
            else if (element is InsertElement insertElem)
            {
                Table table = Program.RelationManager.GetTable(insertElem.TableDefinition.Id);

                options.Add(new QueryPlanNode(insertElem, new InsertOperation(insertElem, table)), 0);
            }

            if (options.Count == 0)
            {
                throw new Exception();
            }

            return(options);
        }
コード例 #24
0
 /*
  * Логическое И принимает на вход два сигнала и выдает положительное состояние,
  * если оба состояния на входе положительны.
  */
 protected void Logical_and(LogicalElement A, LogicalElement B)
 {
     state = (A.state && B.state);
 }
コード例 #25
0
 public TopOperation(LogicalElement logicalElement, PhysicalOperation inputOperation, int?amount)
     : base(logicalElement)
 {
     Left    = inputOperation;
     _amount = amount;
 }
コード例 #26
0
 public LogicalElement(LogicalElement leftChild, LogicalElement rightChild) : this()
 {
     LeftChild  = leftChild;
     RightChild = rightChild;
 }
コード例 #27
0
 /*
  * Отображает сигнал на входе
  */
 public void Logical_output(LogicalElement A)
 {
     state = A.state;
 }
コード例 #28
0
 public ProjectionOperation(LogicalElement logicalElement, PhysicalOperation inputOperation, List <AttributeDefinition> projectionColumns)
     : base(logicalElement)
 {
     Left = inputOperation;
     _projectionColumns = projectionColumns;
 }
コード例 #29
0
 public PhysicalOperation(LogicalElement logicalElement)
 {
     LogicalElement = logicalElement;
 }
コード例 #30
0
 /*
  * Логическое И принимает на вход два сигнала и выдает положительное состояние,
  * если хотя бы одно состояние на входе положительно.
  */
 public void Logical_or(LogicalElement A, LogicalElement B)
 {
     state = (A.state || B.state);
 }