예제 #1
0
        public static uint AssignmentCost(Matrix <uint> cost, IEnumerable <long> assignment)
        {
            if (cost == null)
            {
                throw new ArgumentNullException(nameof(cost));
            }
            if (cost.Rows != cost.Columns)
            {
                throw new ArgumentException($"{cost.Rows} must equal to {cost.Columns}");
            }

            using (var vector = new VectorOfLong(assignment))
            {
                uint result;
                var  type = cost.MatrixElementType.ToNativeMatrixElementType();
                var  ret  = Native.assignment_cost(
                    type,
                    cost.NativePtr,
                    vector.NativePtr,
                    out result);
                if (ret == Native.ErrorType.MatrixElementTypeNotSupport)
                {
                    throw new ArgumentException($"{cost.MatrixElementType} is not supported.");
                }

                return(result);
            }
        }
예제 #2
0
        public static IEnumerable <long> MaxCostAssignment <T>(Matrix <T> cost)
            where T : struct
        {
            if (cost == null)
            {
                throw new ArgumentNullException(nameof(cost));
            }
            if (cost.Rows != cost.Columns)
            {
                throw new ArgumentException($"{cost.Rows} must equal to {cost.Columns}");
            }

            using (var vector = new VectorOfLong())
            {
                var type = cost.MatrixElementType.ToNativeMatrixElementType();
                var ret  = Native.max_cost_assignment(
                    type,
                    cost.NativePtr,
                    vector.NativePtr);
                if (ret == Native.ErrorType.MatrixElementTypeNotSupport)
                {
                    throw new ArgumentException($"{cost.MatrixElementType} is not supported.");
                }

                return(vector.ToArray());
            }
        }
예제 #3
0
        public void CreateWithSize()
        {
            const int size   = 10;
            var       vector = new VectorOfLong(size);

            this.DisposeAndCheckDisposedState(vector);
        }
예제 #4
0
        public void CreateWithCollection()
        {
            const int size   = 10;
            var       source = Enumerable.Range(0, size).Select(s => (long)s).ToArray();
            var       vector = new VectorOfLong(source);

            Assert.AreEqual(vector.Size, size);
            var ret = vector.ToArray();

            for (var i = 0; i < size; i++)
            {
                Assert.AreEqual(ret[i], i);
            }
            this.DisposeAndCheckDisposedState(vector);
        }
예제 #5
0
        public void Create()
        {
            var vector = new VectorOfLong();

            this.DisposeAndCheckDisposedState(vector);
        }