Пример #1
0
        public void TestQuadrilateralOneWay()
        {
            // build graph.
            var graph = new DirectedMetaGraph(ContractedEdgeDataSerializer.Size,
                                              ContractedEdgeDataSerializer.MetaSize);

            graph.AddEdge(0, 2, 100, true, Constants.NO_VERTEX);
            graph.AddEdge(2, 0, 100, false, Constants.NO_VERTEX);
            graph.AddEdge(0, 3, 10, false, Constants.NO_VERTEX);
            graph.AddEdge(3, 0, 10, true, Constants.NO_VERTEX);
            graph.AddEdge(1, 2, 1000, false, Constants.NO_VERTEX);
            graph.AddEdge(2, 1, 1000, true, Constants.NO_VERTEX);
            graph.AddEdge(1, 3, 10000, true, Constants.NO_VERTEX);
            graph.AddEdge(3, 1, 10000, false, Constants.NO_VERTEX);
            graph.Compress();

            // create a witness calculator and the priority calculator.
            var contractedFlags    = new BitArray32(graph.VertexCount);
            var priorityCalculator = new EdgeDifferencePriorityCalculator(graph,
                                                                          new WitnessCalculatorMock(new uint[][]
            {
                new uint[] { 1, 3, 2, 1 },
                new uint[] { 3, 0, 1, 1 }
            }));

            Assert.AreEqual(0, priorityCalculator.Calculate(contractedFlags, 0));
            Assert.AreEqual(0, priorityCalculator.Calculate(contractedFlags, 1));
            Assert.AreEqual(0, priorityCalculator.Calculate(contractedFlags, 2));
            Assert.AreEqual(0, priorityCalculator.Calculate(contractedFlags, 3));
        }
Пример #2
0
        }               // public string DisplayBitMaskFromMultilineString (2 OF 2)

        #endregion      // Public Instance Methods


        #region Private Instance Methods
        private void InitializeInstance(
            int pintTypeInfoIndex,
            object pbytBitMask,
            BitArray32.BitDisplayOrder penmBitDisplayOrder)
        {
            _bclTypeInfo = BitHelpers.s_abclintegertypeinfo [pintTypeInfoIndex];

            _objUnderlyingInteger = pbytBitMask;
            _enmBitDisplayOrder   = penmBitDisplayOrder;

            _strDecimalRepresentation = string.Format(
                FORMAT_FIRST_ITEM_AS_DECIMAL,
                _objUnderlyingInteger);
            _strHexadecimalRepresentation = BitArray32.FormatIntegerAsHex(_objUnderlyingInteger);

            _strTens = BitArray32.GetRulerTens(
                (BitArray32.BitCount)_bclTypeInfo.CapacityInBits,
                _enmBitDisplayOrder);
            _strUnits = BitArray32.GetRulerUnits(
                (BitArray32.BitCount)_bclTypeInfo.CapacityInBits,
                _enmBitDisplayOrder);
            _strArrayOfBits = string.Format(
                new WizardWrx.BitMaskFormat( ),
                _enmBitDisplayOrder == BitArray32.BitDisplayOrder.LowBitToHighBit
                                        ? FORMAT_FIRST_ITEM_AS_REVERSED_BIT_ARRAY :
                FORMAT_FIRST_ITEM_AS_BIT_ARRAY,
                _objUnderlyingInteger);
        }               // private void InitializeInstance
Пример #3
0
        public void TestQuadrilateralOneWay()
        {
            // build graph.
            var graph = new DirectedDynamicGraph(ContractedEdgeDataSerializer.DynamicFixedSize);

            graph.AddEdge(0, 2, 100, true);
            graph.AddEdge(2, 0, 100, false);
            graph.AddEdge(0, 3, 10, false);
            graph.AddEdge(3, 0, 10, true);
            graph.AddEdge(1, 2, 1000, false);
            graph.AddEdge(2, 1, 1000, true);
            graph.AddEdge(1, 3, 10000, true);
            graph.AddEdge(3, 1, 10000, false);
            graph.Compress();

            // create a witness calculator and the priority calculator.
            var contractedFlags    = new BitArray32(graph.VertexCount);
            var priorityCalculator = new EdgeDifferencePriorityCalculator(graph,
                                                                          new Itinero.Algorithms.Contracted.EdgeBased.Witness.DykstraWitnessCalculator(10));

            //var priorityCalculator = new EdgeDifferencePriorityCalculator(graph,
            //    new WitnessCalculatorMock(new uint[][]
            //        {
            //            new uint[] { 1, 3, 2, 1 },
            //            new uint[] { 3, 0, 1, 1 }
            //        }));

            Assert.AreEqual(0, priorityCalculator.Calculate(contractedFlags, (i) => null, 0));
            Assert.AreEqual(0, priorityCalculator.Calculate(contractedFlags, (i) => null, 1));
            Assert.AreEqual(0, priorityCalculator.Calculate(contractedFlags, (i) => null, 2));
            Assert.AreEqual(0, priorityCalculator.Calculate(contractedFlags, (i) => null, 3));
        }
        private static void TestBitArray32()
        {
            Span <uint> tmp = new uint[4096];

            var array = BitArray32.Allocate(4096, 4);

            array.Set(8, 3);
            array.Set(9, 3);
            array.Set(10, 3);
            uint e = array.Get(9);

            array.Set(32 + 6, 3);
            array.Set(510, 2);

            ulong sum = 0;

            sum = (uint)array.Get(0, tmp.Slice(0, 511));

            for (int i = 0; i < 1024; i++)
            {
                sum += (uint)array.Get(0, tmp);
            }

            Console.WriteLine(array + " " + sum);
        }
Пример #5
0
 public void SetBits(int bit, int range, BitArray32 data)
 {
     for (int i = 0; i < range; i++)
     {
         bits.Set(bit + i, data[i]);
     }
 }
Пример #6
0
 public void Save(Context context)
 {
     if (context.ExportMode || updateAttr[Constants.updateAttrCreated])
     {
         GmCommand cmd = context.TargetConn.CreateCommandById("insertIntoGisRanges");
         cmd.AddInt("Id", id);
         cmd.AddInt("TypeId", type.Id);
         context.Buf.SetRect(cmd.AddBinary("Code"), bounds);
         cmd.ExecuteNonQuery();
         if (!context.ExportMode)
         {
             updateAttr = 0;
         }
     }
     if (context.Filter == null)
     {
         return;
     }
     if (!context.Filter.Includes(BatchLevel.Object))
     {
         return;
     }
     if (objects != null)
     {
         foreach (GObject obj in objects)
         {
             obj.Save(context);
         }
     }
 }
Пример #7
0
 internal View(Context context, IDataReader dr)
 {
     lib  = context.Lib;
     id   = dr.GetInt32((int)ViewField.Id);
     attr = dr.GetInt32((int)ViewField.Attr);
     name = dr.GetString((int)ViewField.Name);
     Init(context.Buf.GetIntArray(dr, (int)ViewField.Code));
 }
Пример #8
0
 public Layer(string name, Layer layer)
 {
     lib       = layer.lib;
     id        = lib.GenerateId(this, ref updateAttr);
     this.name = name;
     Clear();
     Merge(layer);
     updateAttr = 0;
 }
Пример #9
0
        internal View(Context context, BinaryReader br)
        {
            lib = context.Lib;
            id  = br.ReadInt32();
//			context.Lib.UpdateGen(this);
            attr = br.ReadInt32();
            name = br.ReadString();
            Init(context.Buf.ReadIntArray(br));
        }
Пример #10
0
 public Layer(Context context, IDataReader dr)
 {
     lib  = context.Lib;
     id   = dr.GetInt32((int)LayerField.Id);
     attr = dr.GetInt32((int)LayerField.Attr);
     name = dr.GetString((int)LayerField.Name);
     int[] typeIds = context.Buf.GetIntArray(dr, (int)LayerField.Code);
     Add(typeIds);
     updateAttr = 0;
 }
Пример #11
0
 public Layer(Context context, BinaryReader br)
 {
     lib  = context.Lib;
     id   = br.ReadInt32();
     attr = br.ReadInt32();
     name = br.ReadString();
     int[] typeIds = context.Buf.ReadIntArray(br);
     Add(typeIds);
     updateAttr = 0;
 }
Пример #12
0
        public BitArray32 GetBits(int bit, int range)
        {
            BitArray32 output = new BitArray32();

            for (int i = 0; i < range; i++)
            {
                output[i] = bits.Get(bit + i);
            }
            return(output);
        }
        // TODO: dont allow public constructor, use a chunk manager/provider instead

        public LocalChunk(IChunkColumn parent, int y, IBlockPalette blockPalette, BlockState airBlock)
        {
            // TODO: validate Y through a chunk manager or something
            Y = y;

            Column       = parent ?? throw new ArgumentNullException(nameof(parent));
            BlockPalette = blockPalette ?? throw new ArgumentNullException(nameof(blockPalette));
            AirBlock     = airBlock;

            // TODO: pool storage arrays
            _blocks = BitArray32.AllocateUninitialized(BlockCount, BlockPalette.BitsPerBlock);
        }
Пример #14
0
        void Read(Context context, BinaryReader br)
        {
            id = br.ReadInt32();
//			context.Lib.UpdateGen(this);
            attr    = br.ReadInt32();
            name    = br.ReadString();
            caption = br.ReadString();
            context.SetStyle(br.ReadString(), ref styleStr, ref style);
            textAttr = br.ReadString();
            ReadCode(context, br);
            range.Add(this);
        }
Пример #15
0
 internal BgImage(Context context, IDataReader dr)
 {
     lib  = context.Lib;
     id   = dr.GetInt32((int)BgImageField.Id);
     attr = dr.GetInt32((int)BgImageField.Attr);
     context.SetStyle(dr.GetString((int)BgImageField.Style), ref styleStr, ref style);
     textAttr = dr.GetString((int)BgImageField.TextAttr);
     filePath = dr.GetString((int)BgImageField.FilePath);
     smin     = dr.GetInt32((int)BgImageField.SMin);
     smax     = dr.GetInt32((int)BgImageField.SMax);
     Init(context.Buf.GetIntArray(dr, (int)BgImageField.Code));
 }
Пример #16
0
        internal BgImage(Context context, BinaryReader br)
        {
            lib = context.Lib;
            id  = br.ReadInt32();
//			lib.UpdateGen(this);
            attr = br.ReadInt32();
            context.SetStyle(br.ReadString(), ref styleStr, ref style);
            textAttr = br.ReadString();
            filePath = br.ReadString();
            smin     = br.ReadInt32();
            smax     = br.ReadInt32();
            Init(context.Buf.ReadIntArray(br));
        }
Пример #17
0
        public void TestOneNeighboursContracted()
        {
            // build graph.
            var graph = new DirectedDynamicGraph(ContractedEdgeDataSerializer.DynamicFixedSize);

            graph.AddEdge(0, 1, 100, true);
            graph.AddEdge(1, 0, 100, false);

            // create a witness calculator and the priority calculator.
            var contractedFlags = new BitArray32(graph.VertexCount);

            contractedFlags[1] = true;
            var priorityCalculator = new EdgeDifferencePriorityCalculator(graph,
                                                                          new WitnessCalculatorMock());
            var priority = priorityCalculator.Calculate(contractedFlags, (i) => null, 0);

            Assert.AreEqual(-2, priority);
        }
Пример #18
0
 public void Save(Context context)
 {
     if (this.IsOverall)
     {
         return;
     }
     if (context.ExportMode || updateAttr[Constants.updateAttrCreated])
     {
         GmCommand cmd = context.TargetConn.CreateCommandById("insertIntoGisViews");
         cmd.AddInt("Id", id);
         cmd.AddInt("Attr", attr);
         cmd.AddString("Name", name, MaxLength.Name);
         context.Buf.SetIntArray(cmd.AddBinary("Code"), GetIntArray());
         cmd.ExecuteNonQuery();
     }
     else if (updateAttr.NonEmpty)
     {
         GmCommand cmd     = context.Conn.CreateCommand();
         string    cmdText = "";
         if (updateAttr[(int)ViewField.Attr])
         {
             cmdText += "Attr= @Attr,";
             cmd.AddInt("Attr", attr);
         }
         if (updateAttr[(int)ViewField.Name])
         {
             cmdText += "Name= @Name,";
             cmd.AddString("Name", name, MaxLength.Name);
         }
         if (updateAttr[(int)ViewField.Code])
         {
             cmdText += "Code= @Code,";
             context.Buf.SetIntArray(cmd.AddBinary("Code"), this.GetIntArray());
         }
         Geomethod.StringUtils.RemoveLastChar(ref cmdText);
         cmd.CommandText = "update gisViews set " + cmdText + " where Id= @Id";
         cmd.AddInt("Id", id);
         cmd.ExecuteNonQuery();
     }
     if (!context.ExportMode)
     {
         updateAttr = 0;
     }
 }
Пример #19
0
        void Init(Context context, IDataReader dr)
        {
            id   = dr.GetInt32((int)ObjectField.Id);
            attr = dr.GetInt32((int)ObjectField.Attr);
//      DZ      16.01.09

//			name= dr.GetString((int)ObjectField.Name);
            name = dr.IsDBNull((int)ObjectField.Name) ? "" : dr.GetString((int)ObjectField.Name);
//			caption=dr.GetString((int)ObjectField.Caption);
            caption = dr.IsDBNull((int)ObjectField.Caption) ? "" : dr.GetString((int)ObjectField.Caption);
//			context.SetStyle(dr.GetString((int)ObjectField.Style),ref styleStr,ref style);
            context.SetStyle(
                dr.IsDBNull((int)ObjectField.Style) ? "" : dr.GetString((int)ObjectField.Style), ref styleStr, ref style);
//			textAttr=dr.GetString((int)ObjectField.TextAttr);
            textAttr = dr.IsDBNull((int)ObjectField.TextAttr) ? "" : dr.GetString((int)ObjectField.TextAttr);

//			this.range=range;
            GetCode(context, dr);
        }
Пример #20
0
        public void TestOneNeighboursNotifyContracted()
        {
            // build graph.
            var graph = new DirectedMetaGraph(ContractedEdgeDataSerializer.Size,
                                              ContractedEdgeDataSerializer.MetaSize);

            graph.AddEdge(0, 1, 100, true, Constants.NO_VERTEX);
            graph.AddEdge(1, 0, 100, false, Constants.NO_VERTEX);

            // create a witness calculator and the priority calculator.
            var contractedFlags = new BitArray32(graph.VertexCount);

            contractedFlags[1] = true;
            var priorityCalculator = new EdgeDifferencePriorityCalculator(graph,
                                                                          new WitnessCalculatorMock());

            priorityCalculator.NotifyContracted(1);
            var priority = priorityCalculator.Calculate(contractedFlags, 0);

            Assert.AreEqual(1, priority);
        }
Пример #21
0
    static void Main(string[] args)
    {
        BitArray32 bits = new BitArray32();

        bits[0] = 1;
        bits[5] = 1;
        bits[5] = 0;
        bits[25] = 1;
        bits[31] = 1;

        for (int i = 0; i <= 31; i++)
        {
            Console.WriteLine("arr[{0}] = {1}", i, bits[i]);
        }

        Console.Write("bits = ");
        for (int i = 0; i <= 31; i++)
        {
            Console.Write(bits[i]);
        }
        Console.WriteLine();
    }
Пример #22
0
    static void Main(string[] args)
    {
        BitArray32 bits = new BitArray32();

        bits[0]  = 1;
        bits[5]  = 1;
        bits[5]  = 0;
        bits[25] = 1;
        bits[31] = 1;

        for (int i = 0; i <= 31; i++)
        {
            Console.WriteLine("arr[{0}] = {1}", i, bits[i]);
        }

        Console.Write("bits = ");
        for (int i = 0; i <= 31; i++)
        {
            Console.Write(bits[i]);
        }
        Console.WriteLine();
    }
Пример #23
0
    public static void Main()
    {
        var bits = new BitArray32();

        bits[0] = 1;
        Console.WriteLine($"bits = {bits}");
        bits[5] = 1;
        Console.WriteLine($"bits = {bits}");
        bits[5] = 0;
        Console.WriteLine($"bits = {bits}");
        bits[25] = 1;
        Console.WriteLine($"bits = {bits}");
        bits[31] = 1;
        Console.WriteLine($"bits = {bits}");

        for (var i = 0; i <= 31; i++)
        {
            Console.WriteLine("arr[{0}] = {1}", i, bits[i]);
        }

        Console.WriteLine($"bits = {bits}");
    }
Пример #24
0
 public void Save(Context context)
 {
     if (context.ExportMode || updateAttr[Constants.updateAttrCreated])
     {
         GmCommand cmd = context.TargetConn.CreateCommandById("insertIntoGisColors");
         cmd.AddInt("Id", id);
         cmd.AddString("Name", name, MaxLength.Name);
         cmd.AddInt("Val", color.ToArgb());
         cmd.ExecuteNonQuery();
     }
     else
     {
         if (updateAttr.IsEmpty)
         {
             return;
         }
         GmCommand cmd     = context.Conn.CreateCommand();
         string    cmdText = "";
         cmd.AddInt("Id", id);
         if (updateAttr[(int)ColorField.Name])
         {
             cmdText += "Name=@Name,";
             cmd.AddString(Name, name, MaxLength.Name);
         }
         if (updateAttr[(int)ColorField.Val])
         {
             cmdText += "Val=@Val,";
             cmd.AddInt("Val", color.ToArgb());
         }
         Geomethod.StringUtils.RemoveLastChar(ref cmdText);
         cmd.CommandText = "update gisColors set " + cmdText + " where Id=@Id";
         cmd.AddInt("Id", id);
         cmd.ExecuteNonQuery();
     }
     if (!context.ExportMode)
     {
         updateAttr = 0;
     }
 }
Пример #25
0
 public void Save(Context context)
 {
     if (context.ExportMode || updateAttr[Constants.updateAttrCreated])
     {
         GmCommand cmd = context.TargetConn.CreateCommandById("insertIntoGisBg");
         cmd.AddInt("Id", id);
         cmd.AddInt("Attr", attr);
         cmd.AddString("Style", styleStr, MaxLength.Style);
         cmd.AddString("TextAttr", textAttr, MaxLength.TextAttr);
         cmd.AddString("FilePath", filePath, MaxLength.FilePath);
         cmd.AddInt("SMin", smin);
         cmd.AddInt("SMax", smax);
         context.Buf.SetIntArray(cmd.AddBinary("Code"), GetIntArray());
         cmd.ExecuteNonQuery();
     }
     else if (updateAttr.NonEmpty)
     {
         GmCommand cmd     = context.Conn.CreateCommand();
         string    cmdText = "";
         if (updateAttr[(int)BgImageField.Attr])
         {
             cmdText += "Attr= @Attr,";
             cmd.AddInt("Attr", attr);
         }
         if (updateAttr[(int)BgImageField.Style])
         {
             cmdText += "Style= @Style,";
             cmd.AddString("Style", styleStr, MaxLength.Style);
         }
         if (updateAttr[(int)BgImageField.TextAttr])
         {
             cmdText += "TextAttr= @TextAttr,";
             cmd.AddString("TextAttr", textAttr, MaxLength.TextAttr);
         }
         if (updateAttr[(int)BgImageField.FilePath])
         {
             cmdText += "FilePath= @FilePath,";
             cmd.AddString("FilePath", filePath, MaxLength.FilePath);
         }
         if (updateAttr[(int)BgImageField.SMin])
         {
             cmdText += "SMin= @SMin,";
             cmd.AddInt("SMin", smin);
         }
         if (updateAttr[(int)BgImageField.SMax])
         {
             cmdText += "SMax= @SMax,";
             cmd.AddInt("SMax", smax);
         }
         if (updateAttr[(int)BgImageField.Code])
         {
             cmdText += "Code= @Code,";
             context.Buf.SetIntArray(cmd.AddBinary("Code"), this.GetIntArray());
         }
         Geomethod.StringUtils.RemoveLastChar(ref cmdText);
         cmd.CommandText = "update gisBg set " + cmdText + " where Id= @Id";
         cmd.AddInt("Id", id);
         cmd.ExecuteNonQuery();
     }
     if (!context.ExportMode)
     {
         updateAttr = 0;
     }
 }
 static void Main(string[] args)
 {
     BitArray32 bits = new BitArray32(54);
     bits.SetBitAt(1, 0);
     Console.WriteLine(bits.GetBit(0));
 }
        /// <summary>
        /// Calculates the priority of the given vertex.
        /// </summary>
        public float Calculate(BitArray32 contractedFlags, Func <uint, IEnumerable <uint[]> > getRestrictions, uint vertex)
        {
            var removed = 0;
            var added   = 0;

            // get and keep edges.
            var edges = new List <DynamicEdge>(_graph.GetEdgeEnumerator(vertex));

            // check if this vertex has a potential restrictions.
            var restrictions    = getRestrictions(vertex);
            var hasRestrictions = restrictions != null && restrictions.Any();

            // remove 'downward' edge to vertex.
            var i = 0;

            while (i < edges.Count)
            {
                var edgeEnumerator = _graph.GetEdgeEnumerator(edges[i].Neighbour);
                edgeEnumerator.Reset();
                while (edgeEnumerator.MoveNext())
                {
                    if (edgeEnumerator.Neighbour == vertex)
                    {
                        removed++;
                    }
                }

                if (contractedFlags[edges[i].Neighbour])
                { // neighbour was already contracted, remove 'downward' edge and exclude it.
                    edgeEnumerator.MoveTo(vertex);
                    edgeEnumerator.Reset();
                    while (edgeEnumerator.MoveNext())
                    {
                        if (edgeEnumerator.Neighbour == edges[i].Neighbour)
                        {
                            removed++;
                        }
                    }
                    edges.RemoveAt(i);
                }
                else
                { // move to next edge.
                    i++;
                }
            }

            // loop over all edge-pairs once.
            for (var j = 1; j < edges.Count; j++)
            {
                var edge1 = edges[j];

                bool?edge1Direction;
                var  edge1Weight          = _weightHandler.GetEdgeWeight(edge1, out edge1Direction);
                var  edge1CanMoveForward  = edge1Direction == null || edge1Direction.Value;
                var  edge1CanMoveBackward = edge1Direction == null || !edge1Direction.Value;

                // figure out what witness paths to calculate.
                var forwardWitnesses  = new EdgePath <T> [j];
                var backwardWitnesses = new EdgePath <T> [j];
                var targets           = new List <uint>(j);
                var targetWeights     = new List <T>(j);
                for (var k = 0; k < j; k++)
                {
                    var edge2 = edges[k];

                    bool?edge2Direction;
                    var  edge2Weight          = _weightHandler.GetEdgeWeight(edge2, out edge2Direction);
                    var  edge2CanMoveForward  = edge2Direction == null || edge2Direction.Value;
                    var  edge2CanMoveBackward = edge2Direction == null || !edge2Direction.Value;

                    if (!(edge1CanMoveBackward && edge2CanMoveForward))
                    {
                        forwardWitnesses[k] = new EdgePath <T>();
                    }
                    if (!(edge1CanMoveForward && edge2CanMoveBackward))
                    {
                        backwardWitnesses[k] = new EdgePath <T>();
                    }
                    targets.Add(edge2.Neighbour);
                    if (hasRestrictions)
                    { // weight can potentially be bigger.
                        targetWeights.Add(_weightHandler.Infinite);
                    }
                    else
                    { // weight can max be the sum of the two edges.
                        targetWeights.Add(_weightHandler.Add(edge1Weight, edge2Weight));
                    }
                }

                // calculate all witness paths.
                _witnessCalculator.Calculate(_graph, getRestrictions, edge1.Neighbour, targets, targetWeights,
                                             ref forwardWitnesses, ref backwardWitnesses, Constants.NO_VERTEX);

                // add contracted edges if needed.
                for (var k = 0; k < j; k++)
                {
                    var edge2 = edges[k];

                    var removedLocal = 0;
                    var addedLocal   = 0;
                    if (forwardWitnesses[k].HasVertex(vertex) && backwardWitnesses[k].HasVertex(vertex))
                    { // add bidirectional edge.
                        _graph.TryAddOrUpdateEdge(edge1.Neighbour, edge2.Neighbour,
                                                  _weightHandler.GetMetric(targetWeights[k]), null, vertex, out addedLocal, out removedLocal);
                        added   += addedLocal;
                        removed += removedLocal;
                        _graph.TryAddOrUpdateEdge(edge2.Neighbour, edge1.Neighbour,
                                                  _weightHandler.GetMetric(targetWeights[k]), null, vertex, out addedLocal, out removedLocal);
                        added   += addedLocal;
                        removed += removedLocal;
                    }
                    else if (forwardWitnesses[k].HasVertex(vertex))
                    { // add forward edge.
                        _graph.TryAddOrUpdateEdge(edge1.Neighbour, edge2.Neighbour,
                                                  _weightHandler.GetMetric(targetWeights[k]), true, vertex, out addedLocal, out removedLocal);
                        added   += addedLocal;
                        removed += removedLocal;
                        _graph.TryAddOrUpdateEdge(edge2.Neighbour, edge1.Neighbour,
                                                  _weightHandler.GetMetric(targetWeights[k]), false, vertex, out addedLocal, out removedLocal);
                        added   += addedLocal;
                        removed += removedLocal;
                    }
                    else if (backwardWitnesses[k].HasVertex(vertex))
                    { // add forward edge.
                        _graph.TryAddOrUpdateEdge(edge1.Neighbour, edge2.Neighbour,
                                                  _weightHandler.GetMetric(targetWeights[k]), false, vertex, out addedLocal, out removedLocal);
                        added   += addedLocal;
                        removed += removedLocal;
                        _graph.TryAddOrUpdateEdge(edge2.Neighbour, edge1.Neighbour,
                                                  _weightHandler.GetMetric(targetWeights[k]), true, vertex, out addedLocal, out removedLocal);
                        added   += addedLocal;
                        removed += removedLocal;
                    }
                }
            }

            var contracted = 0;

            _contractionCount.TryGetValue(vertex, out contracted);
            var depth = 0;

            _depth.TryGetValue(vertex, out depth);
            return(this.DifferenceFactor * (added - removed) + (this.DepthFactor * depth) +
                   (this.ContractedFactor * contracted));
        }
Пример #28
0
        public static ModifyComponentPatch Allocate(IGameComponent leftComponent, IGameComponent comp, BitArray32 mask)
        {
            var rc = ObjectAllocatorHolder <ModifyComponentPatch> .Allocate();

            rc.CreateGameComponent(comp.GetComponentId());
            (rc.Component as INetworkObject).CopyFrom(comp);
            rc.CreateLastGameComponent(comp.GetComponentId());
            (rc.LastComponent as INetworkObject).CopyFrom(leftComponent);
            rc._bitMask = mask;
            return(rc);
        }
Пример #29
0
 public float Calculate(BitArray32 contractedFlags, Func <uint, IEnumerable <uint[]> > getRestrictions, uint vertex)
 {
     return(_priorities[vertex]);
 }
Пример #30
0
        private BitArray32 _restrictionFlags; // contains flags for restricted vertices.

        /// <summary>
        /// Excutes the actual run.
        /// </summary>
        protected override void DoRun()
        {
            _queue            = new BinaryHeap <uint>((uint)_graph.VertexCount);
            _contractedFlags  = new BitArray32(_graph.VertexCount);
            _restrictionFlags = new BitArray32(_graph.VertexCount);
            _missesQueue      = new Queue <bool>();

            // build restrictions flags.
            for (uint i = 0; i < _graph.VertexCount; i++)
            {
                var restrictions = _getRestrictions(i);
                if (restrictions != null && restrictions.Any())
                {
                    _restrictionFlags[i] = true;
                }
            }

            // remove all edges that have witness paths, meaning longer than the shortest path
            // between the two ending vertices.
            this.RemoveWitnessedEdges();

            // build queue.
            this.CalculateQueue();

            var next           = this.SelectNext();
            var latestProgress = 0f;
            var current        = 0;
            var total          = _graph.VertexCount;

            while (next != null)
            {
                // contract...
                this.Contract(next.Value);

                // ... and select next.
                next = this.SelectNext();

                // calculate and log progress.
                var progress = (float)(System.Math.Floor(((double)current / (double)total) * 10000) / 100.0);
                if (progress < 99)
                {
                    progress = (float)(System.Math.Floor(((double)current / (double)total) * 100) / 1.0);
                }
                if (progress != latestProgress)
                {
                    latestProgress = progress;

                    int totaEdges         = 0;
                    int totalUncontracted = 0;
                    int maxCardinality    = 0;
                    var neighbourCount    = new Dictionary <uint, int>();
                    for (uint v = 0; v < _graph.VertexCount; v++)
                    {
                        if (!_contractedFlags[v])
                        {
                            neighbourCount.Clear();
                            var edges = _graph.GetEdgeEnumerator(v);
                            if (edges != null)
                            {
                                var edgesCount = edges.Count();
                                totaEdges = edgesCount + totaEdges;
                                if (maxCardinality < edgesCount)
                                {
                                    maxCardinality = edgesCount;
                                }
                            }
                            totalUncontracted++;
                        }
                    }

                    var density = (double)totaEdges / (double)totalUncontracted;
                    _logger.Log(TraceEventType.Information, "Preprocessing... {0}% [{1}/{2}] {3}q #{4} max {5}",
                                progress, current, total, _queue.Count, density, maxCardinality);
                }
                current++;
            }
        }
Пример #31
0
		}	// private static void ListGUIDsInOrder


        private static void TestSpecificBits ( )
        {
            const int STACK = 4;                    // Bit 3
            const int STDERR = 32;                  // Bit 6
            const int METHOD = 1;                   // Bit 1
            const int SOURCE = 2;                   // Bit 2
            const int EVENTLOG = 8;                 // Bit 4
            const int STDOUT = 16;                  // Bit 5

            const int BIT_6 = 6;

            const string MSG_BEGIN = @"Begin TestSpecificBits{0}";
            const string MSG_DONE = @"{0}TestSpecificBits Done{0}";
            const string MSG_TPL_ANTE = @"{3}    Test {0,2} Ante = {1,2} - b32 = {2}";
            const string MSG_TPL_POST = @"            Post = {0,2} - b32 = {1}";
            const string MSG_TPL_BIT_NUMBER = @"    Test {0,2}: Bit Value = {1,3} ({1:x8}) - Bit Number = {2,2}";

            int rintTestNbr = 1;

            Console.WriteLine (
                MSG_BEGIN ,
                Environment.NewLine );

            UInt32 uintBitNumber = BitArray32.BitNumber ( STACK );
            Console.WriteLine (
                MSG_TPL_BIT_NUMBER ,
                rintTestNbr++ ,
                STACK ,
                uintBitNumber );

            uintBitNumber = BitArray32.BitNumber ( STDERR );
            Console.WriteLine (
                MSG_TPL_BIT_NUMBER ,
                rintTestNbr++ ,
                STDERR ,
                uintBitNumber );

            uintBitNumber = BitArray32.BitNumber ( EVENTLOG );
            Console.WriteLine (
                MSG_TPL_BIT_NUMBER ,
                rintTestNbr++ ,
                EVENTLOG ,
                uintBitNumber );

            uintBitNumber = BitArray32.BitNumber ( STDOUT );
            Console.WriteLine (
                MSG_TPL_BIT_NUMBER ,
                rintTestNbr++ ,
                STDOUT ,
                uintBitNumber );

            uintBitNumber = BitArray32.BitNumber ( METHOD );
            Console.WriteLine (
                MSG_TPL_BIT_NUMBER ,
                rintTestNbr++ ,
                METHOD ,
                uintBitNumber );

            byte byt8Bits = STACK | SOURCE;
            WizardWrx.BitMask32 b32 = new WizardWrx.BitMask32 ( byt8Bits );

            Console.WriteLine (
                MSG_TPL_ANTE ,
                new object [ ]
                {
                    rintTestNbr++ ,
                    byt8Bits ,
                    b32 ,
                    Environment.NewLine
                } );
            b32.BitOn ( BIT_6 );
            byt8Bits = ( byte ) b32;
            Console.WriteLine (
                MSG_TPL_POST ,
                byt8Bits ,
                b32 ,
                Environment.NewLine );

            Console.WriteLine (
                MSG_TPL_ANTE ,
                new object [ ]
                {
                    rintTestNbr++ ,
                    byt8Bits ,
                    b32 ,
                    Environment.NewLine
                } );
            b32.BitOff ( BIT_6 );
            byt8Bits = ( byte ) b32;
            Console.WriteLine (
                MSG_TPL_POST ,
                byt8Bits ,
                b32 ,
                Environment.NewLine );

            Console.WriteLine (
                MSG_DONE ,
                Environment.NewLine );
        }   // private static int TestSpecificBits
Пример #32
0
 public int GenerateId(ISerializableObject ser, ref BitArray32 updateAttr)
 {
     updateAttr[Constants.updateAttrCreated] = true;
     SetChanged();
     return(idGenerator.GetId(ser.ClassId));
 }