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);
            }
        }
        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());
            }
        }
Beispiel #3
0
        public void CreateWithSize()
        {
            const int size   = 10;
            var       vector = new VectorOfLong(size);

            this.DisposeAndCheckDisposedState(vector);
        }
Beispiel #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);
        }
Beispiel #5
0
        public void Create()
        {
            var vector = new VectorOfLong();

            this.DisposeAndCheckDisposedState(vector);
        }