Exemplo n.º 1
0
 public override IOperation Apply() {
   ItemArray<IntArray> neighbors = new ItemArray<IntArray>(SwarmSize);
   for (int i = 0; i < SwarmSize; i++) {
     neighbors[i] = new IntArray(new[] { (SwarmSize + i - 1) % SwarmSize, (i + 1) % SwarmSize });
   }
   Neighbors = neighbors;
   return base.Apply();
 }
Exemplo n.º 2
0
        public IntArray ChannelArray()
        {
            var channel = new IntArray(8);

            var ch = new[] {1, 2, 3, 4, 1, 2, 3, 4};
            for(int i = 0; i < ch.Length; i++)
                channel.setitem(i, ch[i]);

            return channel;
        }
Exemplo n.º 3
0
        public void CreateBuffers(int width_, int height_)
        {
            width = width_;
            height = height_;

            cpuBuffer = new FloatArray(width * height * 8);

            // Initial test data for rendering
            for (int y = 0; y < height; y++)
            {
                for (int x = 0; x < width; x++)
                {
                    double coord = Math.Sin(x / 5.0) * 0.01;
                    //coord = sin(y/);

                    int index = (y * width + x) * 8;
                    // Position
                    cpuBuffer[index] = x / ((float)(width - 1));
                    cpuBuffer[index + 1] = (float)coord;
                    cpuBuffer[index + 2] = y / ((float)(height - 1));
                    // Normal
                    cpuBuffer[index + 3] = 1;
                    cpuBuffer[index + 4] = 0;
                    cpuBuffer[index + 5] = 0;
                    // TexCoords
                    cpuBuffer[index + 6] = y / ((float)(height - 1));
                    cpuBuffer[index + 7] = -x / ((float)(width - 1));
                }
            }

            // Generate and fill index array for rendering
            //indices = new IntArray(width * 3 * 2 + 2 + height * width * 3 * 2); // FIXME: what is this?
            indices = new IntArray(3 * 2 * (width - 1) * (height - 1));

            for (int y = 0; y < height - 1; y++)
            {
                for (int x = 0; x < width - 1; x++)
                {
                    // *3 indices/triangle, *2 triangles/quad
                    int baseIndex = (x + y * (width - 1)) * 3 * 2;

                    indices[baseIndex] = x + y * width;
                    indices[baseIndex + 1] = x + 1 + y * width;
                    indices[baseIndex + 2] = x + width + y * width;

                    indices[baseIndex + 3] = indices[baseIndex + 1];
                    indices[baseIndex + 4] = indices[baseIndex] + (width + 1);
                    indices[baseIndex + 5] = indices[baseIndex + 2];
                }
            }
        }
 public override IOperation Apply() {
   ItemArray<IntArray> neighbors = new ItemArray<IntArray>(SwarmSize);
   for (int i = 0; i < SwarmSize; i++) {
     var numbers = Enumerable.Range(0, SwarmSize).ToList();
     numbers.RemoveAt(i);
     var selectedNumbers = new List<int>(NrOfConnections);
     for (int j = 0; j < NrOfConnections && numbers.Count > 0; j++) {
       int index = Random.Next(numbers.Count);
       selectedNumbers.Add(numbers[index]);
       numbers.RemoveAt(index);
     }
     neighbors[i] = new IntArray(selectedNumbers.ToArray());
   }
   Neighbors = neighbors;
   return base.Apply();
 }
Exemplo n.º 5
0
        public void ExecuteWithAppend()
        {
            var a1 = new IntArray { Arr = new int[] { 5, 6, 7 }, List = new List<int> { 8, 9, 10 } };
            var model = TypeModel.Create();
            model.AutoCompile = false;
            model.Add(typeof(IntArray), true)[1].OverwriteList = false;
            model.Add(typeof(IntArray), true)[2].OverwriteList = false;

            var clone = (IntArray)model.DeepClone(a1);
            AssertSequence(clone.Arr, "Runtime:Arr", 1, 2, 5, 6, 7);
            AssertSequence(clone.List, "Runtime:List", 3, 4, 8, 9, 10);

            model.CompileInPlace();
            clone = (IntArray)model.DeepClone(a1);
            AssertSequence(clone.Arr, "CompileInPlace:Arr", 1, 2, 5, 6, 7);
            AssertSequence(clone.List, "CompileInPlace:List", 3, 4, 8, 9, 10);

            var precomp = model.Compile();
            clone = (IntArray)precomp.DeepClone(a1);
            AssertSequence(clone.Arr, "Compile:Arr", 1, 2, 5, 6, 7);
            AssertSequence(clone.List, "Compile:List", 3, 4, 8, 9, 10);
        }
Exemplo n.º 6
0
        // Create a sequence of flag objects and add them to the world.
        void CreateFlag(int width, int height, out AlignedSoftBodyArray flags)
        {
            flags = new AlignedSoftBodyArray();

            // First create a triangle mesh to represent a flag

            // Allocate a simple mesh consisting of a vertex array and a triangle index array
            IndexedMesh mesh = new IndexedMesh();
            mesh.NumVertices = width * height;
            mesh.NumTriangles = 2 * (width - 1) * (height - 1);

            Vector3Array vertexArray = new Vector3Array(mesh.NumVertices);
            mesh.Vertices = vertexArray;
            mesh.VertexStride = Vector3.SizeInBytes;

            IntArray triangleVertexIndexArray = new IntArray(3 * mesh.NumTriangles);
            mesh.TriangleIndices = triangleVertexIndexArray;
            mesh.TriangleIndexStride = sizeof(int) * 3;

            // Generate normalised object space vertex coordinates for a rectangular flag

            Matrix defaultScale = Matrix.Scaling(5, 20, 1);
            for (int y = 0; y < height; ++y)
            {
                float yCoordinate = y * 2.0f / (float)height - 1.0f;
                for (int x = 0; x < width; ++x)
                {
                    float xCoordinate = x * 2.0f / (float)width - 1.0f;

                    Vector3 vertex = new Vector3(xCoordinate, yCoordinate, 0.0f);
                    vertexArray[y * width + x] = Vector3.TransformCoordinate(vertex, defaultScale);
                }
            }

            // Generate vertex indices for triangles
            for (int y = 0; y < (height - 1); ++y)
            {
                for (int x = 0; x < (width - 1); ++x)
                {
                    // Triangle 0
                    // Top left of square on mesh
                    {
                        int vertex0 = y * width + x;
                        int vertex1 = vertex0 + 1;
                        int vertex2 = vertex0 + width;
                        int triangleIndex = 2 * (y * (width - 1) + x);
                        triangleVertexIndexArray[(mesh.TriangleIndexStride * triangleIndex) / sizeof(int)] = vertex0;
                        triangleVertexIndexArray[(mesh.TriangleIndexStride * triangleIndex + 1) / sizeof(int) + 1] = vertex1;
                        triangleVertexIndexArray[(mesh.TriangleIndexStride * triangleIndex + 2) / sizeof(int) + 2] = vertex2;
                    }

                    // Triangle 1
                    // Bottom right of square on mesh
                    {
                        int vertex0 = y * width + x + 1;
                        int vertex1 = vertex0 + width;
                        int vertex2 = vertex1 - 1;
                        int triangleIndex = 2 * y * (width - 1) + 2 * x + 1;
                        triangleVertexIndexArray[(mesh.TriangleIndexStride * triangleIndex) / sizeof(int)] = vertex0;
                        triangleVertexIndexArray[(mesh.TriangleIndexStride * triangleIndex) / sizeof(int) + 1] = vertex1;
                        triangleVertexIndexArray[(mesh.TriangleIndexStride * triangleIndex) / sizeof(int) + 2] = vertex2;
                    }
                }
            }

            Matrix defaultRotateAndScale = Matrix.RotationX(0.5f);

            // Construct the sequence flags applying a slightly different translation to each one to arrange them
            // appropriately in the scene.
            for (int i = 0; i < numFlags; ++i)
            {
                float zTranslate = flagSpacing * (i - numFlags / 2);

                Vector3 defaultTranslate = new Vector3(0, 20, zTranslate);
                Matrix transform = defaultRotateAndScale * Matrix.Translation(defaultTranslate);

                SoftBody softBody = CreateFromIndexedMesh(vertexArray, triangleVertexIndexArray, true);

                for (int j = 0; j < mesh.NumVertices; ++j)
                {
                    softBody.SetMass(j, 10.0f / mesh.NumVertices);
                }
                softBody.SetMass((height - 1) * width, 0);
                softBody.SetMass((height - 1) * width + width - 1, 0);
                softBody.SetMass((height - 1) * width + width / 2, 0);
                softBody.Cfg.Collisions = FCollisions.CLSS | FCollisions.CLRS;

                softBody.Cfg.LF = 0.0005f;
                softBody.Cfg.VCF = 0.001f;
                softBody.Cfg.DP = 0.0f;
                softBody.Cfg.DG = 0.0f;

                flags.Add(softBody);

                softBody.Transform(transform);

                SoftWorld.AddSoftBody(softBody);
            }

            //delete [] vertexArray;
            //delete [] triangleVertexIndexArray;
        }
        protected override void DrawVisualization(Bitmap bitmap)
        {
            DoubleMatrix coordinates            = Content.Coordinates;
            DoubleMatrix distanceMatrix         = Content.DistanceMatrix;
            BoolValue    useDistanceMatrix      = Content.UseDistanceMatrix;
            DoubleArray  dueTime                = Content.DueTime;
            DoubleArray  serviceTime            = Content.ServiceTime;
            DoubleArray  readyTime              = Content.ReadyTime;
            DoubleArray  demand                 = Content.Demand;
            IntArray     pickupDeliveryLocation = Content.PickupDeliveryLocation;

            Pen flowPen = new Pen(Brushes.Red, 3);

            flowPen.EndCap    = System.Drawing.Drawing2D.LineCap.ArrowAnchor;
            flowPen.DashStyle = System.Drawing.Drawing2D.DashStyle.Dot;

            if ((coordinates != null) && (coordinates.Rows > 0) && (coordinates.Columns == 2))
            {
                double xMin = double.MaxValue, yMin = double.MaxValue, xMax = double.MinValue, yMax = double.MinValue;
                for (int i = 0; i < coordinates.Rows; i++)
                {
                    if (xMin > coordinates[i, 0])
                    {
                        xMin = coordinates[i, 0];
                    }
                    if (yMin > coordinates[i, 1])
                    {
                        yMin = coordinates[i, 1];
                    }
                    if (xMax < coordinates[i, 0])
                    {
                        xMax = coordinates[i, 0];
                    }
                    if (yMax < coordinates[i, 1])
                    {
                        yMax = coordinates[i, 1];
                    }
                }

                int    border = 20;
                double xStep  = xMax != xMin ? (bitmap.Width - 2 * border) / (xMax - xMin) : 1;
                double yStep  = yMax != yMin ? (bitmap.Height - 2 * border) / (yMax - yMin) : 1;

                using (Graphics graphics = Graphics.FromImage(bitmap)) {
                    if (Solution != null)
                    {
                        int currentTour = 0;

                        List <Tour> tours = Solution.GetTours();
                        List <Pen>  pens  = GetColors(tours.Count);

                        foreach (Tour tour in tours)
                        {
                            double  t                   = 0.0;
                            Point[] tourPoints          = new Point[tour.Stops.Count + 2];
                            Brush[] customerBrushes     = new Brush[tour.Stops.Count];
                            Pen[]   customerPens        = new Pen[tour.Stops.Count];
                            bool[]  validPickupDelivery = new bool[tour.Stops.Count];
                            int     lastCustomer        = 0;

                            Dictionary <int, bool> stops = new Dictionary <int, bool>();
                            for (int i = -1; i <= tour.Stops.Count; i++)
                            {
                                int location = 0;

                                if (i == -1 || i == tour.Stops.Count)
                                {
                                    location = 0; //depot
                                }
                                else
                                {
                                    location = tour.Stops[i];
                                }

                                Point locationPoint = new Point(border + ((int)((coordinates[location, 0] - xMin) * xStep)),
                                                                bitmap.Height - (border + ((int)((coordinates[location, 1] - yMin) * yStep))));
                                tourPoints[i + 1] = locationPoint;

                                if (i != -1 && i != tour.Stops.Count)
                                {
                                    Brush customerBrush = Brushes.Black;
                                    Pen   customerPen   = Pens.Black;

                                    t += Content.GetDistance(
                                        lastCustomer, location, Solution);

                                    if (t < readyTime[location])
                                    {
                                        t             = readyTime[location];
                                        customerBrush = Brushes.Orange;
                                        customerPen   = Pens.Orange;
                                    }
                                    else if (t > dueTime[location])
                                    {
                                        customerBrush = Brushes.Red;
                                        customerPen   = Pens.Red;
                                    }

                                    t += serviceTime[location];

                                    validPickupDelivery[i] =
                                        ((demand[location] >= 0) ||
                                         (stops.ContainsKey(pickupDeliveryLocation[location])));

                                    customerBrushes[i] = customerBrush;
                                    customerPens[i]    = customerPen;

                                    stops.Add(location, true);
                                }
                                lastCustomer = location;
                            }

                            if (!drawFlow)
                            {
                                graphics.DrawPolygon(pens[currentTour], tourPoints);
                            }

                            for (int i = 0; i < tour.Stops.Count; i++)
                            {
                                if (validPickupDelivery[i])
                                {
                                    graphics.FillRectangle(customerBrushes[i], tourPoints[i + 1].X - 3, tourPoints[i + 1].Y - 3, 6, 6);

                                    if (demand[tour.Stops[i]] < 0 && drawFlow)
                                    {
                                        int location = pickupDeliveryLocation[tour.Stops[i]];
                                        int source   = tour.Stops.IndexOf(location);

                                        graphics.DrawLine(flowPen, tourPoints[source + 1], tourPoints[i + 1]);
                                    }
                                }
                                else
                                {
                                    graphics.DrawRectangle(customerPens[i], tourPoints[i + 1].X - 3, tourPoints[i + 1].Y - 3, 6, 6);
                                }
                            }

                            graphics.FillEllipse(Brushes.Blue, tourPoints[0].X - 5, tourPoints[0].Y - 5, 10, 10);

                            currentTour++;
                        }

                        for (int i = 0; i < pens.Count; i++)
                        {
                            pens[i].Dispose();
                        }
                    }
                    else
                    {
                        {
                            Point[] locationPoints = new Point[coordinates.Rows];
                            //just draw customers
                            for (int i = 1; i < coordinates.Rows; i++)
                            {
                                locationPoints[i] = new Point(border + ((int)((coordinates[i, 0] - xMin) * xStep)),
                                                              bitmap.Height - (border + ((int)((coordinates[i, 1] - yMin) * yStep))));

                                graphics.FillRectangle(Brushes.Black, locationPoints[i].X - 3, locationPoints[i].Y - 3, 6, 6);
                            }

                            if (drawFlow)
                            {
                                for (int i = 1; i < coordinates.Rows; i++)
                                {
                                    if (demand[i] < 0)
                                    {
                                        graphics.DrawLine(flowPen, locationPoints[pickupDeliveryLocation[i]], locationPoints[i]);
                                    }
                                }
                            }

                            Point locationPoint = new Point(border + ((int)((coordinates[0, 0] - xMin) * xStep)),
                                                            bitmap.Height - (border + ((int)((coordinates[0, 1] - yMin) * yStep))));
                            graphics.FillEllipse(Brushes.Blue, locationPoint.X - 5, locationPoint.Y - 5, 10, 10);
                        }
                    }
                }
            }

            flowPen.Dispose();
        }
Exemplo n.º 8
0
        public override ECFieldElement Invert()
        {
            // Inversion in F2m using the extended Euclidean algorithm
             // Input: A nonzero polynomial a(z) of degree at most m-1
             // Output: a(z)^(-1) mod f(z)

             // u(z) := a(z)
             IntArray uz = (IntArray)this.x.Clone();

             // v(z) := f(z)
             IntArray vz = new IntArray(t);
             vz.SetBit(m);
             vz.SetBit(0);
             vz.SetBit(this.k1);
             if (this.representation == Ppb) {
            vz.SetBit(this.k2);
            vz.SetBit(this.k3);
             }

             // g1(z) := 1, g2(z) := 0
             IntArray g1z = new IntArray(t);
             g1z.SetBit(0);
             IntArray g2z = new IntArray(t);

             // while u != 0
             while (uz.GetUsedLength() > 0)
            //            while (uz.bitLength() > 1)
             {
            // j := deg(u(z)) - deg(v(z))
            int j = uz.BitLength - vz.BitLength;

            // If j < 0 then: u(z) <-> v(z), g1(z) <-> g2(z), j := -j
            if (j < 0) {
               IntArray uzCopy = uz;
               uz = vz;
               vz = uzCopy;

               IntArray g1zCopy = g1z;
               g1z = g2z;
               g2z = g1zCopy;

               j = -j;
            }

            // u(z) := u(z) + z^j * v(z)
            // Note, that no reduction modulo f(z) is required, because
            // deg(u(z) + z^j * v(z)) <= max(deg(u(z)), j + deg(v(z)))
            // = max(deg(u(z)), deg(u(z)) - deg(v(z)) + deg(v(z))
            // = deg(u(z))
            // uz = uz.xor(vz.ShiftLeft(j));
            // jInt = n / 32
            int jInt = j >> 5;
            // jInt = n % 32
            int jBit = j & 0x1F;
            IntArray vzShift = vz.ShiftLeft(jBit);
            uz.AddShifted(vzShift, jInt);

            // g1(z) := g1(z) + z^j * g2(z)
            //                g1z = g1z.xor(g2z.ShiftLeft(j));
            IntArray g2zShift = g2z.ShiftLeft(jBit);
            g1z.AddShifted(g2zShift, jInt);
             }
             return new F2mFieldElement(this.m, this.k1, this.k2, this.k3, g2z);
        }
Exemplo n.º 9
0
        /**
         * Constructor for Ppb.
         * @param m  The exponent <code>m</code> of
         * <code>F<sub>2<sup>m</sup></sub></code>.
         * @param k1 The integer <code>k1</code> where <code>x<sup>m</sup> +
         * x<sup>k3</sup> + x<sup>k2</sup> + x<sup>k1</sup> + 1</code>
         * represents the reduction polynomial <code>f(z)</code>.
         * @param k2 The integer <code>k2</code> where <code>x<sup>m</sup> +
         * x<sup>k3</sup> + x<sup>k2</sup> + x<sup>k1</sup> + 1</code>
         * represents the reduction polynomial <code>f(z)</code>.
         * @param k3 The integer <code>k3</code> where <code>x<sup>m</sup> +
         * x<sup>k3</sup> + x<sup>k2</sup> + x<sup>k1</sup> + 1</code>
         * represents the reduction polynomial <code>f(z)</code>.
         * @param x The BigInteger representing the value of the field element.
         */
        public F2mFieldElement(
         int         m,
         int         k1,
         int         k2,
         int         k3,
         BigInteger  x)
        {
            // t = m / 32 rounded up to the next integer
             this.t = (m + 31) >> 5;
             this.x = new IntArray(x, t);

             if ((k2 == 0) && (k3 == 0)) {
            this.representation = Tpb;
             } else {
            if (k2 >= k3) {
               throw new System.ArgumentException("k2 must be smaller than k3");
            }
            if (k2 <= 0) {
               throw new System.ArgumentException("k2 must be larger than 0");
            }

            this.representation = Ppb;
             }

             if (x.SignValue < 0) {
            throw new System.ArgumentException("x value cannot be negative");
             }

             this.m = m;
             this.k1 = k1;
             this.k2 = k2;
             this.k3 = k3;
        }
Exemplo n.º 10
0
 public void Swap(IntArray data)
 {
     Swap(data.values[0], data.values[1]);
 }
        public static KnapsackEvaluation Apply(BinaryVector v, IntValue capacity, DoubleValue penalty, IntArray weights, IntArray values)
        {
            if (weights.Length != values.Length)
            {
                throw new InvalidOperationException("The weights and values parameters of the Knapsack problem have different sizes");
            }

            KnapsackEvaluation result = new KnapsackEvaluation();

            double quality = 0;

            int    weight         = 0;
            int    value          = 0;
            double appliedPenalty = 0;

            for (int i = 0; i < v.Length; i++)
            {
                if (v[i])
                {
                    weight += weights[i];
                    value  += values[i];
                }
            }

            if (weight > capacity.Value)
            {
                appliedPenalty = penalty.Value * (weight - capacity.Value);
            }

            quality = value - appliedPenalty;

            result.AppliedPenalty = new DoubleValue(appliedPenalty);
            result.SumWeights     = new DoubleValue(weight);
            result.SumValues      = new DoubleValue(value);
            result.Quality        = new DoubleValue(quality);

            return(result);
        }
Exemplo n.º 12
0
 public bool Get(string name, IntArray data)
 {
     var ss = new ScriptString(name);
     return Global_GetAnyData(ss.ThisPtr, data.ThisPtr);
 }
Exemplo n.º 13
0
 public virtual Critter AddNpc(ushort pid, ushort hx, ushort hy, Direction dir, IntArray parameters, IntArray items, string script)
 {
     return (Critter)Map_AddNpc(thisptr, pid, hx, hy, (byte)dir, (IntPtr)parameters, (IntPtr)items, (IntPtr)((ScriptString)script));
 }
Exemplo n.º 14
0
    public static KnapsackEvaluation Apply(BinaryVector v, IntValue capacity, DoubleValue penalty, IntArray weights, IntArray values) {
      if (weights.Length != values.Length)
        throw new InvalidOperationException("The weights and values parameters of the Knapsack problem have different sizes");

      KnapsackEvaluation result = new KnapsackEvaluation();

      double quality = 0;

      int weight = 0;
      int value = 0;
      double appliedPenalty = 0;

      for (int i = 0; i < v.Length; i++) {
        if (v[i]) {
          weight += weights[i];
          value += values[i];
        }
      }

      if (weight > capacity.Value) {
        appliedPenalty = penalty.Value * (weight - capacity.Value);
      }

      quality = value - appliedPenalty;

      result.AppliedPenalty = new DoubleValue(appliedPenalty);
      result.SumWeights = new DoubleValue(weight);
      result.SumValues = new DoubleValue(value);
      result.Quality = new DoubleValue(quality);

      return result;
    }
Exemplo n.º 15
0
 public static IJavaObject newInstance(Class<IJavaObject> arg0, IntArray arg1)
 {
     return Static.CallMethod<IJavaObject>(typeof(Array), "newInstance", "(Ljava/lang/Class;[I)Ljava/lang/Object;", arg0, arg1);
 }
Exemplo n.º 16
0
 public virtual void SetInternalBag(UInt16Array pids, UIntArray min_counts, UIntArray max_counts, IntArray slots)
 {
     Crit_SetInternalBag(thisptr, pids.ThisPtr, min_counts.ThisPtr, max_counts.ThisPtr, slots.ThisPtr);
 }
Exemplo n.º 17
0
 public virtual void RunClientScript(string func_name, int p0, int p1, int p2, string p3, IntArray p4)
 {
     var func_name_ = new ScriptString(func_name);
     var p3_ = p3 != null ? new ScriptString(p3) : null;
     Cl_RunClientScript(thisptr, func_name_.ThisPtr, p0, p1, p2,
         p3_ != null ? p3_.ThisPtr : IntPtr.Zero,
         p4 != null ? p4.ThisPtr : IntPtr.Zero);
 }
Exemplo n.º 18
0
 public virtual uint GetTimeEvents(IntArray find_identifiers, IntArray identifiers, UIntArray indexes, UIntArray durations, UIntArray rates)
 {
     return Crit_GetTimeEventsArr(thisptr, (IntPtr)find_identifiers, (IntPtr)identifiers, (IntPtr)indexes, (IntPtr)durations, (IntPtr)rates);
 }
Exemplo n.º 19
0
        SoftBody CreateFromIndexedMesh(Vector3Array vertexArray, IntArray triangleVertexIndexArray, bool createBendLinks)
        {
            SoftBody softBody = new SoftBody(SoftWorld.WorldInfo, vertexArray, null);
            Material structuralMaterial = softBody.AppendMaterial();
            Material bendMaterial;
            if (createBendLinks)
            {
                bendMaterial = softBody.AppendMaterial();
                bendMaterial.Lst = 0.7f;
            }
            else
            {
                bendMaterial = null;
            }
            structuralMaterial.Lst = 1.0f;

            int numVertices = vertexArray.Count;
            int numTriangles = triangleVertexIndexArray.Count / 3;

            // List of values for each link saying which triangle is associated with that link
            // -1 to start. Once a value is entered we know the "other" triangle
            // and can add a link across the link
            AlignedIntArray triangleForLinks = new AlignedIntArray();
            triangleForLinks.Resize(numVertices * numVertices, -1);

            for (int triangle = 0; triangle < numTriangles; ++triangle)
            {
                int[] index = new int[] { triangleVertexIndexArray[triangle * 3], triangleVertexIndexArray[triangle * 3 + 1], triangleVertexIndexArray[triangle * 3 + 2] };
                softBody.AppendFace(index[0], index[1], index[2]);

                // Generate the structural links directly from the triangles
                TestAndAddLink(triangleForLinks, softBody, triangle, triangleVertexIndexArray, numVertices, index[0], index[1], index[2], structuralMaterial, createBendLinks, bendMaterial);
                TestAndAddLink(triangleForLinks, softBody, triangle, triangleVertexIndexArray, numVertices, index[1], index[2], index[0], structuralMaterial, createBendLinks, bendMaterial);
                TestAndAddLink(triangleForLinks, softBody, triangle, triangleVertexIndexArray, numVertices, index[2], index[0], index[1], structuralMaterial, createBendLinks, bendMaterial);
            }

            return softBody;
        }
Exemplo n.º 20
0
 public Permutation(PermutationTypes type, IntArray elements)
   : this(type, elements.Length) {
   for (int i = 0; i < array.Length; i++)
     array[i] = elements[i];
 }
Exemplo n.º 21
0
 public uint GetBagItems(uint bag_id, UInt16Array pids, UIntArray min_counts, UIntArray max_counts, IntArray slots)
 {
     return Global_GetBagItems(bag_id, (IntPtr)pids, (IntPtr)min_counts, (IntPtr)max_counts, (IntPtr)slots);
 }
Exemplo n.º 22
0
 public IntArrayDocIdSet(int length)
 {
     array = new IntArray(length);
 }
Exemplo n.º 23
0
        public void ShouldReturnZeroInCaseNoElementIsAdded()
        {
            var array = new IntArray();

            Assert.Equal(0, array.Count);
        }
Exemplo n.º 24
0
 protected KnapsackSolution(KnapsackSolution original, Cloner cloner)
   : base(original, cloner) {
   this.binaryVector = cloner.Clone(original.binaryVector);
   this.quality = cloner.Clone(original.quality);
   this.capacity = cloner.Clone(original.capacity);
   this.weights = cloner.Clone(original.weights);
   this.values = cloner.Clone(original.values);
   Initialize();
 }
Exemplo n.º 25
0
 public KnapsackSolution(BinaryVector binaryVector, DoubleValue quality, IntValue capacity, IntArray weights, IntArray values)
   : base() {
   this.binaryVector = binaryVector;
   this.capacity = capacity;
   this.weights = weights;
   this.values = values;
   this.quality = quality;
   Initialize();
 }
Exemplo n.º 26
0
 public IntegerVector(IntArray elements)
   : this(elements.Length) {
   for (int i = 0; i < array.Length; i++)
     array[i] = elements[i];
 }
Exemplo n.º 27
0
    sais_main(BaseArray T, int[] SA, int fs, int n, int k, bool isbwt)
    {
      BaseArray C, B, RA;
      int i, j, b, m, p, q, name, pidx = 0, newfs;
      int c0, c1;
      uint flags = 0;

      if (k <= MINBUCKETSIZE)
      {
        C = new IntArray(new int[k], 0);
        if (k <= fs) { B = new IntArray(SA, n + fs - k); flags = 1; }
        else { B = new IntArray(new int[k], 0); flags = 3; }
      }
      else if (k <= fs)
      {
        C = new IntArray(SA, n + fs - k);
        if (k <= (fs - k)) { B = new IntArray(SA, n + fs - k * 2); flags = 0; }
        else if (k <= (MINBUCKETSIZE * 4)) { B = new IntArray(new int[k], 0); flags = 2; }
        else { B = C; flags = 8; }
      }
      else
      {
        C = B = new IntArray(new int[k], 0);
        flags = 4 | 8;
      }

      /* stage 1: reduce the problem by at least 1/2
         sort all the LMS-substrings */
      getCounts(T, C, n, k); getBuckets(C, B, k, true); /* find ends of buckets */
      for (i = 0; i < n; ++i) { SA[i] = 0; }
      b = -1; i = n - 1; j = n; m = 0; c0 = T[n - 1];
      do { c1 = c0; } while ((0 <= --i) && ((c0 = T[i]) >= c1));
      for (; 0 <= i; )
      {
        do { c1 = c0; } while ((0 <= --i) && ((c0 = T[i]) <= c1));
        if (0 <= i)
        {
          if (0 <= b) { SA[b] = j; } b = --B[c1]; j = i; ++m;
          do { c1 = c0; } while ((0 <= --i) && ((c0 = T[i]) >= c1));
        }
      }
      if (1 < m)
      {
        LMSsort(T, SA, C, B, n, k);
        name = LMSpostproc(T, SA, n, m);
      }
      else if (m == 1)
      {
        SA[b] = j + 1;
        name = 1;
      }
      else
      {
        name = 0;
      }

      /* stage 2: solve the reduced problem
         recurse if names are not yet unique */
      if (name < m)
      {
        if ((flags & 4) != 0) { C = null; B = null; }
        if ((flags & 2) != 0) { B = null; }
        newfs = (n + fs) - (m * 2);
        if ((flags & (1 | 4 | 8)) == 0)
        {
          if ((k + name) <= newfs) { newfs -= k; }
          else { flags |= 8; }
        }
        for (i = m + (n >> 1) - 1, j = m * 2 + newfs - 1; m <= i; --i)
        {
          if (SA[i] != 0) { SA[j--] = SA[i] - 1; }
        }
        RA = new IntArray(SA, m + newfs);
        sais_main(RA, SA, newfs, m, name, false);
        RA = null;

        i = n - 1; j = m * 2 - 1; c0 = T[n - 1];
        do { c1 = c0; } while ((0 <= --i) && ((c0 = T[i]) >= c1));
        for (; 0 <= i; )
        {
          do { c1 = c0; } while ((0 <= --i) && ((c0 = T[i]) <= c1));
          if (0 <= i)
          {
            SA[j--] = i + 1;
            do { c1 = c0; } while ((0 <= --i) && ((c0 = T[i]) >= c1));
          }
        }

        for (i = 0; i < m; ++i) { SA[i] = SA[m + SA[i]]; }
        if ((flags & 4) != 0) { C = B = new IntArray(new int[k], 0); }
        if ((flags & 2) != 0) { B = new IntArray(new int[k], 0); }
      }

      /* stage 3: induce the result for the original problem */
      if ((flags & 8) != 0) { getCounts(T, C, n, k); }
      /* put all left-most S characters into their buckets */
      if (1 < m)
      {
        getBuckets(C, B, k, true); /* find ends of buckets */
        i = m - 1; j = n; p = SA[m - 1]; c1 = T[p];
        do
        {
          q = B[c0 = c1];
          while (q < j) { SA[--j] = 0; }
          do
          {
            SA[--j] = p;
            if (--i < 0) { break; }
            p = SA[i];
          } while ((c1 = T[p]) == c0);
        } while (0 <= i);
        while (0 < j) { SA[--j] = 0; }
      }
      if (isbwt == false) { induceSA(T, SA, C, B, n, k); }
      else { pidx = computeBWT(T, SA, C, B, n, k); }
      C = null; B = null;
      return pidx;
    }
Exemplo n.º 28
0
 public IntArrayDocIdSet()
 {
     array = new IntArray();
 }
Exemplo n.º 29
0
 static void AddRange()
 {
     var arr = new IntArray(new[] { 0, 1, 2 });
     arr.AddRange(new[] { 3, 4 });
     Tests.Assert(arr.Length == 5, "AddRange array length.");
     Tests.Assert(arr[3] == 3, "AddRange first added element.");
     Tests.Assert(arr[4] == 4, "AddRange last element.");
 }
Exemplo n.º 30
0
        private F2mFieldElement(int m, int k1, int k2, int k3, IntArray x)
        {
            t = (m + 31) >> 5;
             this.x = x;
             this.m = m;
             this.k1 = k1;
             this.k2 = k2;
             this.k3 = k3;

             if ((k2 == 0) && (k3 == 0)) {
            this.representation = Tpb;
             } else {
            this.representation = Ppb;
             }
        }
Exemplo n.º 31
0
 static void Iterating()
 {
     var arr = new IntArray(new [] { 0, 1, 2, 3 });
     bool iter = true;
     int i = 0;
     int c = 0;
     foreach(var e in arr)
     {
         c++;
         if(e != i++)
             iter = false;
     }
     Tests.Assert(iter, "Iterating over value array");
     Tests.Assert(c == arr.Length, "Iteration count");
 }
Exemplo n.º 32
0
 public P4DDocIdSet()
 {
     baseList = new IntArray();
     compressedSet = new P4DSetNoBase();
     compressedBits = 0;
 }
Exemplo n.º 33
0
        // Helper to test and add links correctly.
        // Records links that have already been generated
        static bool TestAndAddLink(AlignedIntArray trianglesForLinks, SoftBody softBody, int triangle, IntArray triangleVertexIndexArray, int numVertices, int vertex0, int vertex1, int nonLinkVertex, Material structuralMaterial, bool createBendLinks, Material bendMaterial)
        {
            if (trianglesForLinks[numVertices * vertex0 + vertex1] >= 0 && createBendLinks)
            {
                // Already have link so find other triangle and generate cross link

                int otherTriangle = trianglesForLinks[numVertices * vertex0 + vertex1];
                int[] otherIndices = new int[] { triangleVertexIndexArray[otherTriangle * 3], triangleVertexIndexArray[otherTriangle * 3 + 1], triangleVertexIndexArray[otherTriangle * 3 + 2] };

                int nodeA = 0;
                // Test all links of the other triangle against this link. The one that's not part of it is what we want.
                if (otherIndices[0] != vertex0 && otherIndices[0] != vertex1)
                    nodeA = otherIndices[0];
                if (otherIndices[1] != vertex0 && otherIndices[1] != vertex1)
                    nodeA = otherIndices[1];
                if (otherIndices[2] != vertex0 && otherIndices[2] != vertex1)
                    nodeA = otherIndices[2];

                softBody.AppendLink(nodeA, nonLinkVertex, bendMaterial);
            }
            else
            {
                // Don't yet have link so create it
                softBody.AppendLink(vertex0, vertex1, structuralMaterial);

                // If we added a new link, set the triangle array
                trianglesForLinks[numVertices * vertex0 + vertex1] = triangle;
                trianglesForLinks[numVertices * vertex1 + vertex0] = triangle;

            }

            return true;
        }
Exemplo n.º 34
0
 public AtomicIntegerArray(IntArray arg0)
     : base(ProxyCtor.I)
 {
     Instance.CallConstructor("([I)V", arg0);
 }
        public object GetMany(int id, int id2, int id3, int id4, int id5)
        {
            try
            {
                var quizzClassLessonId = id;
                var pageNum            = id2;
                var numPerPage         = id3;

                var quizzClass = _uow.QuizzClassLessons.GetAll()
                                 .Where(qcl => qcl.Id == quizzClassLessonId)
                                 .Select(qcl => qcl.QuizzClass)
                                 .ProjectTo <QuizzClassModel>(new { userId = _currentUser.Id })
                                 .FirstOrDefault();

                quizzClass.Member = _uow.QuizzClassMembers.GetAll()
                                    .Where(qcm => qcm.Id == quizzClass.QuizzClassMemberId)
                                    .ProjectTo <QuizzClassMemberModel>()
                                    .FirstOrDefault();

                var list = _uow.QuizzClassLessonComments.GetAll()
                           .Where(qclm => qclm.QuizzClassLessonId == quizzClassLessonId && qclm.IsDeleted == false)
                           .OrderByDescending(qca => qca.PostedDate)
                           .Skip((pageNum - 1) * numPerPage)
                           .Take(numPerPage)
                           .ProjectTo <QuizzClassLessonCommentModel>(new { userId = _currentUser.Id })
                           .ToList();

                foreach (var item in list)
                {
                    if (item.IsAuthor)
                    {
                        item.IsQuizzmate = true;
                    }
                    item.AuthorName = item.IsQuizzmate ? item.AuthorFullName : item.AuthorUserName;
                    item.PostedDate = item.PostedDate.ToLocalTime();

                    SetAge(item);
                }

                var quizzClassLessonIdx = _uow.QuizzClassLessons.GetAll()
                                          .Where(qcl => qcl.Id == quizzClassLessonId)
                                          .Select(qcl => qcl.QuizzClassLesssonIdx)
                                          .FirstOrDefault();


                var intArrayHelper = new IntArray(quizzClass.Member.NewLessonCommentCount);
                var count          = intArrayHelper.GetAtIndex(quizzClassLessonIdx);
                if (count > 0)
                {
                    _svcContainer.QuizzClassMemberUpdateSvc.RemoveClassLessonDiscussion(quizzClass.Id, quizzClassLessonIdx, count, true);
                }
                foreach (var item in list)
                {
                    item.IsNew = count-- > 0;
                }

                return(list);
            }
            catch (Exception ex)
            {
                _svcContainer.LoggingSvc.Log(ex);
                return(null);
            }
        }