protected override void drawNode(Node iNode, AbstractVector iPosition)
 {
     // Draw the given node according to given position
     //GameObject nodeObj = Instantiate(Resources.Load("Node") as GameObject, new Vector3(iPosition.x, iPosition.y, iPosition.z), Quaternion.identity, graphHolder);
     //nodeObj.name = iNode.Data.label;
     iNode.Data.gameObject.transform.position = new Vector3(iPosition.x, iPosition.y, iPosition.z);
 }
Beispiel #2
0
 public Particle(AbstractVector iPosition, AbstractVector iVelocity, AbstractVector iAcceleration, INode iNode)
 {
     Position     = iPosition;
     Node         = iNode;
     Velocity     = iVelocity;
     Acceleration = iAcceleration;
 }
            public void UpdateVisual(AbstractVector vec)
            {
                var newPos = Reference.TransformPoint(PositionToVector3(vec));

                newPos.y        = Reference.position.y;
                Visual.position = newPos;
            }
    static object SliderFuncVector <T, ElemType>(object v, object min, object max, ref string unparsedStr, string label = "", string[] elemLabels = null)
    {
        var vec    = new AbstractVector(v);
        var minVec = new AbstractVector(min);
        var maxVec = new AbstractVector(max);

        var elementNum = vec.GetElementNum();
        var eLabels    = elemLabels ?? defaultElemLabelsVector;

        using (var h0 = new GUILayout.HorizontalScope())
        {
            if (!string.IsNullOrEmpty(label))
            {
                GUILayout.Label(label);
            }
            using (var vertical = new GUILayout.VerticalScope())
            {
                var strs = SplitUnparsedStr(unparsedStr, elementNum);
                for (var i = 0; i < elementNum; ++i)
                {
                    using (var h1 = new GUILayout.HorizontalScope())
                    {
                        var elem = Slider((ElemType)vec[i], (ElemType)minVec[i], (ElemType)maxVec[i], ref strs[i], eLabels[i]);
                        vec[i] = elem;
                    }
                }
                unparsedStr = JoinUnparsedStr(strs);
            }
        }

        return(v);
    }
        public void DrawBox(Node iNode, AbstractVector iPosition)
        {
            Pair <int, int> pos = GraphToScreen(iPosition as FDGVector2);

            m_fdgBoxes[iNode].Set(pos.first, pos.second);
            m_fdgBoxes[iNode].DrawBox(paper);
        }
Beispiel #6
0
    static object SliderFuncVector <T>(object v, object min, object max, ref string unparsedStr, string label = "", string[] elemLabels = null)
    {
        var elementNum = AbstractVector.GetElementNum <T>();
        var eLabels    = elemLabels ?? defaultElemLabelsVector;

        using (var h0 = new GUILayout.HorizontalScope())
        {
            if (!string.IsNullOrEmpty(label))
            {
                GUILayout.Label(label);
            }
            using (var vertical = new GUILayout.VerticalScope())
            {
                var strs = SplitUnparsedStr(unparsedStr, elementNum);
                for (var i = 0; i < elementNum; ++i)
                {
                    using (var h1 = new GUILayout.HorizontalScope())
                    {
                        var elem = Slider(AbstractVector.GetAtIdx <T>(v, i), AbstractVector.GetAtIdx <T>(min, i), AbstractVector.GetAtIdx <T>(max, i), ref strs[i], eLabels[i]);
                        v = AbstractVector.SetAtIdx <T>(v, i, elem);
                    }
                }
                unparsedStr = JoinUnparsedStr(strs);
            }
        }

        return(v);
    }
        public void DrawLine(Edge iEdge, AbstractVector iPosition1, AbstractVector iPosition2)
        {
            Pair <int, int> pos1 = GraphToScreen(iPosition1 as FDGVector2);
            Pair <int, int> pos2 = GraphToScreen(iPosition2 as FDGVector2);

            m_fdgLines[iEdge].Set(pos1.first, pos1.second, pos2.first, pos2.second);
            m_fdgLines[iEdge].DrawLine(paper);
        }
Beispiel #8
0
    protected override void drawNode(Node iNode, AbstractVector iPosition)
    {
        // Draw the given node according to given position
        Function f = controller.nodes [ulong.Parse(iNode.Data.label)] as Function;

        f.nx = iPosition.x;
        f.ny = iPosition.y;
        f.nz = iPosition.z;
    }
Beispiel #9
0
        public static void Set(string key, object val)
        {
            var keys = GenerateKeys(key);

            for (var i = 0; i < keys.Count; ++i)
            {
                PlayerPrefsStrandard <float> .Set(keys[i], AbstractVector.GetAtIdx <T>(val, i));
            }
        }
    protected override void drawNode(Node iNode, AbstractVector iPosition)
    {
        if (controller.gameNodes.ContainsKey(iNode.ID))
        {
            GameObject gameNode = controller.gameNodes[iNode.ID];

            // use localPosition, since you can determine the precise location by the transform of the gameobject which these
            // nodes are child of
            gameNode.transform.localPosition = new Vector3(iPosition.x * controller.ScaleFactor, iPosition.y * controller.ScaleFactor, iPosition.z * controller.ScaleFactor);
        }
    }
Beispiel #11
0
        public static void Set(string key, object val)
        {
            var vec = new AbstractVector(val);

            var keys = GenerateKeys(key);

            for (var i = 0; i < keys.Count; ++i)
            {
                PlayerPrefsStrandard <ElemType> .Set(keys[i], vec[i]);
            }
        }
Beispiel #12
0
    static object FieldFuncVector <T>(object v, ref string unparsedStr, params GUILayoutOption[] options)
    {
        var elementNum = AbstractVector.GetElementNum <T>();
        var strs       = SplitUnparsedStr(unparsedStr, elementNum);

        for (var i = 0; i < elementNum; ++i)
        {
            var elem = Field(AbstractVector.GetAtIdx <T>(v, i), ref strs[i], "", options);
            v = AbstractVector.SetAtIdx <T>(v, i, elem);
        }
        unparsedStr = JoinUnparsedStr(strs);
        return(v);
    }
Beispiel #13
0
        static List <string> GenerateKeys(string key)
        {
            List <string> ret;

            if (!_keyCache.TryGetValue(key, out ret))
            {
                var num = AbstractVector.GetElementNum <T>();
                ret            = Enumerable.Range(0, num).Select((i) => key + "_" + i + "_PlayerPrefsVector").ToList();
                _keyCache[key] = ret;
            }

            return(ret);
        }
Beispiel #14
0
    static object FieldFuncVector <T, ElemType>(object v, ref string unparsedStr, params GUILayoutOption[] options)
    {
        var vec        = new AbstractVector(v);
        var elementNum = vec.GetElementNum();
        var strs       = SplitUnparsedStr(unparsedStr, elementNum);

        for (var i = 0; i < elementNum; ++i)
        {
            var val = Field((ElemType)vec[i], ref strs[i], "", options);
            vec[i] = val;
        }
        unparsedStr = JoinUnparsedStr(strs);
        return(v);
    }
Beispiel #15
0
        public static object Get(string key, object defaultValue)
        {
            object ret = default(T);

            var keys = GenerateKeys(key);

            for (var i = 0; i < keys.Count; ++i)
            {
                var elem = (float)PlayerPrefsStrandard <float> .Get(keys[i], AbstractVector.GetAtIdx <T>(defaultValue, i));

                ret = AbstractVector.SetAtIdx <T>(ret, i, elem);
            }
            return(ret);
        }
        public static void Print(AbstractVector polyCoeffs)
        {
            if (polyCoeffs == null)
            {
                throw new ArgumentNullException("polyCoeffs", "Vector can not be null.");
            }

            Console.Write("lambda^{0} - ", polyCoeffs.Length);
            for (int i = polyCoeffs.Length; i > 1; i--)
            {
                Console.Write("{0} * lambda^{1} - ", polyCoeffs[polyCoeffs.Length - i], i - 1);
            }
            Console.Write(polyCoeffs[polyCoeffs.Length - 1]);
            Console.WriteLine();
        }
Beispiel #17
0
        public static object Get(string key, object defaultValue)
        {
            object ret        = default(T);
            var    defaultVec = new AbstractVector(defaultValue);
            var    retVec     = new AbstractVector(ret);

            var keys = GenerateKeys(key);

            for (var i = 0; i < keys.Count; ++i)
            {
                var elem = (ElemType)PlayerPrefsStrandard <ElemType> .Get(keys[i], defaultVec[i]);

                retVec[i] = elem;
            }
            return(ret);
        }
    protected override void drawEdge(Edge iEdge, AbstractVector iPosition1, AbstractVector iPosition2)
    {
        if (controller.gameNodes.ContainsKey(iEdge.ID))
        {
            GameObject gameEdge = controller.gameNodes[iEdge.ID];

            GameObject source = controller.gameNodes[iEdge.Source.ID];
            GameObject target = controller.gameNodes[iEdge.Target.ID];

            LineRenderer line = gameEdge.GetComponent <LineRenderer>();

            if (source != null && target != null & line != null)
            {
                line.SetPositions(new Vector3[] { source.transform.position, target.transform.position });
            }
        }
    }
        protected override void drawEdge(Edge iEdge, AbstractVector iPosition1, AbstractVector iPosition2)
        {
            // Draw the given edge according to given positions

            //LineRenderer lineRenderer = GetComponent<LineRenderer>();
            //lineRenderer.SetPosition(0, new Vector3(iPosition1.x, iPosition1.y, iPosition1.z));
            //lineRenderer.SetPosition(1, new Vector3(iPosition2.x, iPosition2.y, iPosition2.z));

            //GameObject edgeObj = Instantiate(Resources.Load("Edge") as GameObject, Vector3.zero, Quaternion.identity, graphHolder);
            //NodeEdge nodeEdge = edgeObj.GetComponent<NodeEdge>();
            //nodeEdge.node1 = new Vector3(iPosition1.x, iPosition1.y, iPosition1.z);
            //nodeEdge.node2 = new Vector3(iPosition2.x, iPosition2.y, iPosition2.z);

            //LineRenderer lineRenderer = edgeObj.GetComponent<LineRenderer>();
            //lineRenderer.SetPosition(0, nodeEdge.node1);
            //lineRenderer.SetPosition(1, nodeEdge.node2);
        }
Beispiel #20
0
    static object SliderFuncColor <T, ElemType>(object v, object min, object max, ref string unparsedStr, string label = "", string[] elemLabels = null)
    {
        var vec = new AbstractVector(v);

        var elementNum = vec.GetElementNum();
        var eLabels    = elemLabels ?? defaultElemLabelsColor;

        Vector4 v4 = default(Vector4);
        Color   c  = new Color((float)vec[0], (float)vec[1], (float)vec[2], (float)vec[3]);

        Color.RGBToHSV(c, out v4.x, out v4.y, out v4.z);
        v4.w = c.a;

        using (var h0 = new GUILayout.HorizontalScope())
        {
            if (!string.IsNullOrEmpty(label))
            {
                GUILayout.Label(label);
            }

            using (var vertical = new GUILayout.VerticalScope())
            {
                var strs = SplitUnparsedStr(unparsedStr, elementNum);
                for (var i = 0; i < 4; ++i)
                {
                    using (var h1 = new GUILayout.HorizontalScope())
                    {
                        var elem = Slider(v4[i], 0, 1, ref strs[i], eLabels[i]);
                        v4[i] = elem;
                    }
                }
                unparsedStr = JoinUnparsedStr(strs);
            }

            using (var cs = new GUIUtil.ColorScope(c))
            {
                GUILayout.Label("■■■");
            }
        }

        var col = Color.HSVToRGB(v4[0], v4[1], v4[2]);

        col.a = v4[3];
        return(col);
    }
Beispiel #21
0
        internal LiteralValuePartitionedTableRouter(AbstractVector values, BasicAnyVector locations)
        {
            if (values.DataCategory != Entity_DATA_CATEGORY.LITERAL)
            {
                throw new Exception("expect a vector of literals");
            }
            IList <string> strings = new List <string>();

            for (int i = 0; i < values.rows(); ++i)
            {
                try
                {
                    strings.Add(values.get(i).String);
                }
                catch (Exception e)
                {
                    Console.WriteLine(e.ToString());
                    Console.Write(e.StackTrace);
                    throw new Exception(e);
                }
            }
            initialize(strings, locations);
        }
        internal IntegralRangePartitionedTableRouter(AbstractVector values, BasicAnyVector locations)
        {
            if (values.DataCategory != Entity_DATA_CATEGORY.INTEGRAL)
            {
                throw new Exception("expect a vector of integrals");
            }
            IList <long?> longs = new List <long?>();

            for (int i = 0; i < values.rows(); ++i)
            {
                try
                {
                    longs.Add(Convert.ToInt64(values.get(i).Number.longValue()));
                }
                catch (Exception e)
                {
                    Console.WriteLine(e.ToString());
                    Console.Write(e.StackTrace);
                    throw new Exception(e);
                }
            }
            initialize(longs, locations);
        }
Beispiel #23
0
        public int compress(AbstractVector input, int elementCount, int unitLength, int maxCompressedLength, ByteBuffer output)
        {
            if (compresser == null)
            {
                compresser = LZ4Sharp.LZ4CompressorFactory.CreateNew();
            }
            int        byteCount = 0;
            int        dataCount = input.rows();
            int        dataIndex = 0;
            ByteBuffer dataBufer = ByteBuffer.Allocate(DEFAULT_BLOCK_SIZE);

            dataBufer.order(output.isLittleEndian);
            int partial = 0, elementNum;

            while (dataCount > dataIndex)
            {
                int readBytes = input.serialize(dataIndex, partial, dataCount - dataIndex, out elementNum, out partial, dataBufer);
                while (readBytes > 0)
                {
                    int    blockSize = Math.Min(DEFAULT_BLOCK_SIZE, dataBufer.ReadableBytes);
                    byte[] srcBuf    = new byte[blockSize];
                    dataBufer.ReadBytes(srcBuf, 0, blockSize);
                    byte[] ret = compresser.Compress(srcBuf);
                    if (ret.Length + sizeof(int) > output.remain())
                    {
                        output.reserve((output.WriterIndex + ret.Length + sizeof(int)) * 2);
                    }
                    output.WriteInt(ret.Length);
                    output.WriteBytes(ret);
                    byteCount += ret.Length + sizeof(int) * 8;
                    readBytes -= blockSize;
                }
                dataIndex += elementNum;
                dataBufer.Clear();
            }
            return(byteCount);
        }
        public int compress(AbstractVector input, int elementCount, int unitLength, int maxCompressedLength, ByteBuffer output)
        {
            DeltaOfDeltaBlockEncoder blockEncoder = new DeltaOfDeltaBlockEncoder(unitLength);
            int        count     = 0;
            int        dataCount = input.rows();
            int        dataIndex = 0;
            ByteBuffer dataBufer = ByteBuffer.Allocate(DEFAULT_BLOCK_SIZE);

            dataBufer.order(output.isLittleEndian);
            int partial = 0, elementNum = 0;

            while (dataCount > dataIndex)
            {
                int readBytes = input.serialize(dataIndex, partial, dataCount - dataIndex, out elementNum, out partial, dataBufer);
                dataIndex += elementNum;
                while (readBytes > 0)
                {
                    int    blockSize  = Math.Min(readBytes, DEFAULT_BLOCK_SIZE);
                    long[] compressed = blockEncoder.compress(dataBufer, blockSize);
                    //write blockSize+data
                    output.WriteInt(compressed.Length * sizeof(long));
                    foreach (long l in compressed)
                    {
                        if (output.remain() < sizeof(long))
                        {
                            output.reserve(output.Capacity * 2);
                        }
                        output.WriteLong(l);
                    }
                    count     += sizeof(int) + compressed.Length * sizeof(long);
                    readBytes -= blockSize;
                    dataBufer.Clear();
                }
            }
            return(count);
        }
 public static TableRouter createRouter(com.xxdb.data.Entity_PARTITION_TYPE type, AbstractVector values, BasicAnyVector locations)
 {
     if (type == com.xxdb.data.Entity_PARTITION_TYPE.RANGE)
     {
         if (values.DataCategory == com.xxdb.data.Entity_DATA_CATEGORY.INTEGRAL)
         {
             return(new IntegralRangePartitionedTableRouter(values, locations));
         }
         else if (values.DataCategory == com.xxdb.data.Entity_DATA_CATEGORY.LITERAL)
         {
             return(new LiteralRangePartitionedTableRouter(values, locations));
         }
     }
     else if (type == com.xxdb.data.Entity_PARTITION_TYPE.VALUE)
     {
         if (values.DataCategory == com.xxdb.data.Entity_DATA_CATEGORY.INTEGRAL)
         {
             return(new IntegralValuePartitionedTableRouter(values, locations));
         }
         else if (values.DataCategory == com.xxdb.data.Entity_DATA_CATEGORY.LITERAL)
         {
             return(new LiteralValuePartitionedTableRouter(values, locations));
         }
     }
     else if (type == com.xxdb.data.Entity_PARTITION_TYPE.LIST)
     {
         BasicAnyVector schema = (BasicAnyVector)values;
         if (schema.getEntity(0).DataCategory == com.xxdb.data.Entity_DATA_CATEGORY.INTEGRAL)
         {
             return(new IntegralListPartitionedTableRouter(values, locations));
         }
         else if (schema.getEntity(0).DataCategory == com.xxdb.data.Entity_DATA_CATEGORY.LITERAL)
         {
             return(new LiteralListPartitionedTableRouter(values, locations));
         }
     }
     throw new Exception("Unsupported partition type " + type.ToString());
 }
Beispiel #26
0
 public void ApplyForce(AbstractVector force)
 {
     Acceleration.Add(force / Mass);
 }
Beispiel #27
0
        public void run()
        {
            Socket socket = this.socket;

            try
            {
                long offset = -1;
                if (bis == null)
                {
                    bis = new BufferedStream(new NetworkStream(socket));
                }
                ExtendedDataInput @in = null;

                while (true)
                {
                    if (@in == null)
                    {
                        bool isLittle = bis.ReadByte() != 0;
                        if (isLittle)
                        {
                            @in = new LittleEndianDataInputStream(bis);
                        }
                        else
                        {
                            @in = new BigEndianDataInputStream(bis);
                        }
                    }
                    else
                    {
                        @in.readBoolean();
                    }

                    @in.readLong();
                    long msgid = @in.readLong();

                    if (offset == -1)
                    {
                        offset = msgid;
                    }
                    topic = @in.readString();
                    short          flag    = @in.readShort();
                    IEntityFactory factory = new BasicEntityFactory();
                    int            form    = flag >> 8;
                    int            type    = flag & 0xff;

                    if (form < 0 || form > MAX_FORM_VALUE)
                    {
                        throw new IOException("Invalid form value: " + form);
                    }
                    if (type < 0 || type > MAX_TYPE_VALUE)
                    {
                        throw new IOException("Invalid type value: " + type);
                    }

                    DATA_FORM df = (DATA_FORM)form;
                    DATA_TYPE dt = (DATA_TYPE)type;

                    IEntity body;
                    try
                    {
                        body = factory.createEntity(df, dt, @in);
                    }
                    catch
                    {
                        throw;
                    }
                    if (body.isTable())
                    {
                        if (body.rows() != 0)
                        {
                            throw new Exception("When message is table, it should be empty.");
                        }
                    }
                    else if (body.isVector())
                    {
                        dispatcher.setMsgId(topic, msgid);
                        BasicAnyVector dTable = (BasicAnyVector)body;

                        int colSize = dTable.rows();
                        int rowSize = dTable.getEntity(0).rows();
                        if (rowSize == 1)
                        {
                            BasicMessage rec = new BasicMessage(msgid, topic, dTable);
                            dispatcher.dispatch(rec);
                        }
                        else if (rowSize > 1)
                        {
                            List <IMessage> messages = new List <IMessage>(rowSize);
                            for (int i = 0; i < rowSize; i++)
                            {
                                BasicAnyVector row = new BasicAnyVector(colSize);

                                for (int j = 0; j < colSize; j++)
                                {
                                    AbstractVector vector = (AbstractVector)dTable.getEntity(j);
                                    IEntity        entity = vector.get(i);
                                    row.setEntity(j, entity);
                                }
                                BasicMessage rec = new BasicMessage(msgid, topic, row);
                                messages.Add(rec);
                                msgid++;
                            }
                            dispatcher.batchDispatch(messages);
                        }
                        offset += rowSize;
                    }
                    else
                    {
                        throw new Exception("message body has an invalid format. Vector or table is expected");
                    }
                }
            }
            catch (Exception)
            {
                if (dispatcher.isClosed(topic))
                {
                    return;
                }
                else
                {
                    dispatcher.tryReconnect(topic);
                }
            }
            finally
            {
                try
                {
                    socket.Close();
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.ToString());
                    Console.Write(ex.StackTrace);
                }
            }
        }
 public static Vector3 PositionToVector3(AbstractVector vector)
 {
     return(new Vector3(vector.x, 0f, vector.y));
 }
Beispiel #29
0
 Vector3 PositionToVector3(AbstractVector vector)
 {
     return(new Vector3(vector.x, vector.y, vector.z));
 }
Beispiel #30
0
 protected override void drawEdge(Edge iEdge, AbstractVector iPosition1, AbstractVector iPosition2)
 {
     // Draw the given edge according to given positions
 }