Exemplo n.º 1
0
 public GLPK(int a, int b)
 {
     this.a = a;
     this.b = b;
     lp = glp_create_prob();
     //Col 1 is x, Col 2 is y
     glp_add_rows(lp, 1);
     glp_add_cols(lp, 2);
     glp_set_col_bnds(lp, 1, GLP_FR, 0.0, 0.0);
     glp_set_col_bnds(lp, 2, GLP_FR, 0.0, 0.0);
     glp_set_col_kind(lp, 1, GLP_IV);
     glp_set_col_kind(lp, 2, GLP_IV);
     //Row 1 is a*x + b*y
     ConstraintMatrix CM = new ConstraintMatrix();
     CM.ia[1]=1; CM.ja[1]=1; CM.ar[1]=a;
     CM.ia[2]=1; CM.ja[2]=2; CM.ar[2]=b;
     glp_load_matrix(lp, 2, CM.ia, CM.ja, CM.ar);
     Console.WriteLine("Hello Nigel");
 }
Exemplo n.º 2
0
 public static extern int RXANBPGetNotch(int channel, int notch, double *fcenter, double *fwidth, int *active);
Exemplo n.º 3
0
 public static extern void GetRXAAGCHangLevel(int channel, double *hanglevel);
Exemplo n.º 4
0
 public unsafe partial void ReferencePlane([Count(Count = 4), Flow(FlowDirection.In)] double *equation);
Exemplo n.º 5
0
 /// <summary>
 /// __m128d _mm_loaddup_pd (double const* mem_addr)
 /// </summary>
 public static unsafe Vector128 <double> LoadAndDuplicate(double *address)
 {
     throw new NotImplementedException();
 }
Exemplo n.º 6
0
 public static extern IppStatus ippsAdd_64f_I(double *pSrc, double *pSrcDst, int len);
Exemplo n.º 7
0
 public static extern IppStatus ippsAddC_64f(double *pSrc, double val, double *pDst, int len);
Exemplo n.º 8
0
 public unsafe Matrix(double[,] data)
 {
     if (data == null) throw new ArgumentNullException("data");
     int rows = data.GetUpperBound(0) + 1;
     int columns = data.GetUpperBound(1) + 1;
     
     _rowCount = rows;
     _columnCount = columns;
     _length = _rowCount * _columnCount;
     Data = (double*)Marshal.AllocHGlobal(_rowCount * _columnCount * sizeof(double));
     for (int r = 0; r < _rowCount; r++)
     {
         for (int c = 0; c < _columnCount; c++)
         {
             this[r, c] = data[r,c];
         }
     }
 }
Exemplo n.º 9
0
 public static extern IppStatus ippsMinMaxIndx_64f(double *pSrc, int len, double *pMin, int *pMinIndx, double *pMax, int *pMaxIndx);
Exemplo n.º 10
0
 public static extern IppStatus ippsSum_64f(double *pSrc, int len, double *pSum);
Exemplo n.º 11
0
 public static extern IppStatus ippsPowx_64f_A53(double *pSrc1, double ConstValue, double *pDst, int len);
Exemplo n.º 12
0
 public static extern IppStatus ippsSet_64f(double val, double *pDst, int len);
Exemplo n.º 13
0
 public static extern int swr_set_matrix(libswresample.SwrContext *s, double *matrix, int stride);
Exemplo n.º 14
0
 protected static extern unsafe IntPtr TypedColumnWriter_WriteBatchSpaced_Double(
     IntPtr columnWriter, long numValues, short *defLevels, short *repLevels, byte *validBits, long validBitsOffset, double *values);
Exemplo n.º 15
0
 //
 // This exists so that I don't have to mark GetNumericValue as being unsafe.
 // The transition from safe to unsafe is something that we don't want untrusted code
 // to have to do.
 //
 internal unsafe static double InternalGetNumericValue(char ch)
 {
     //
     // If we haven't get the unsafe pointers to the numeric table before, do it now.
     //            
     if (m_pNumericDataTable == null) {
         m_pNumericDataTable = nativeGetNumericDataTable();
         m_pNumericLevel2WordOffset = nativeGetNumericLevel2Offset();
         m_pNumericFloatData = nativeGetNumericFloatData();
     }
     // Get the level 2 item from the highest 8 bit (8 - 15) of ch.
     byte index1 = m_pNumericDataTable[ch >> 8];
     // Get the level 2 WORD offset from the 4 - 7 bit of ch.  This provides the base offset of the level 3 table.
     // The offset is referred to an float item in m_pNumericFloatData.
     // Note that & has the lower precedence than addition, so don't forget the parathesis.            
     ushort offset = m_pNumericLevel2WordOffset[(index1 << 4) + ((ch >> 4) & 0x000f)];
     // Get the result from the 0 -3 bit of ch.
     return (m_pNumericFloatData[offset + (ch & 0x000f)]);
 }
Exemplo n.º 16
0
 public static extern IppStatus ippsMean_64f(double *pSrc, int len, double *pMean);
Exemplo n.º 17
0
 public static extern IppStatus ippsReplaceNAN_64f_I(double *pSrcDst, int len, double value);
Exemplo n.º 18
0
 protected static extern unsafe IntPtr TypedColumnWriter_WriteBatch_Double(
     IntPtr columnWriter, long numValues, short *defLevels, short *repLevels, double *values);
Exemplo n.º 19
0
 public static extern IppStatus ippsMeanStdDev_64f(double *pSrc, int len, double *pMean, double *pStdDev);
Exemplo n.º 20
0
 public static extern IppStatus ippsAdd_64f(double *pSrc1, double *pSrc2, double *pDst, int len);
Exemplo n.º 21
0
 public static extern IppStatus ippsDotProd_64f(double *pSrc1, double *pSrc2, int len, double *pDp);
Exemplo n.º 22
0
 public static extern IppStatus ippsMulC_64f_I(double val, double *pSrcDst, int len);
Exemplo n.º 23
0
 public static extern IppStatus ippsAtan_64f_A53(double *pSrc, double *pDst, int len);
Exemplo n.º 24
0
        /*!HC:TYPELIST:
         * <hycalper>
         * <type>
         * <source locate="after">
         * inArr1
         * </source>
         * <destination>complex</destination>
         * <destination>fcomplex</destination>
         * <destination>float</destination>
         * </type>
         * <type>
         * <source locate="after">
         * inArr2
         * </source>
         * <destination>complex</destination>
         * <destination>fcomplex</destination>
         * <destination>float</destination>
         * </type>
         * <type>
         * <source locate="after">
         * outArr1
         * </source>
         * <destination>complex</destination>
         * <destination>fcomplex</destination>
         * <destination>float</destination>
         * </type>
         * <type>
         * <source locate="after">
         * inCls1
         * </source>
         * <destination><![CDATA[ILArray<complex>]]></destination>
         * <destination><![CDATA[ILArray<fcomplex>]]></destination>
         * <destination><![CDATA[ILArray<float>]]></destination>
         * </type>
         * <type>
         * <source locate="after">
         * inCls2
         * </source>
         * <destination><![CDATA[ILArray<complex>]]></destination>
         * <destination><![CDATA[ILArray<fcomplex>]]></destination>
         * <destination><![CDATA[ILArray<float>]]></destination>
         * </type>
         * <type>
         * <source locate="after">
         * outCls1
         * </source>
         * <destination><![CDATA[ILArray<complex>]]></destination>
         * <destination><![CDATA[ILArray<fcomplex>]]></destination>
         * <destination><![CDATA[ILArray<float>]]></destination>
         * </type>
         * <type>
         * <source locate="after">
         * lapackfunc
         * </source>
         * <destination>Lapack.zgemm</destination>
         * <destination>Lapack.cgemm</destination>
         * <destination>Lapack.sgemm</destination>
         * </type>
         * </hycalper>
         */

        /// <summary>
        /// GEneral Matrix Multiply this array
        /// </summary>
        /// <overloads>General Matrix Multiply for double, float, complex and fcomplex arrays</overloads>
        /// <param name="A"><![CDATA[ILArray<>]]> matrix A</param>
        /// <param name="B"><![CDATA[ILArray<>]]> matrix B</param>
        /// <returns><![CDATA[ILArray<double>]]> new array - result of matrix multiplication</returns>
        /// <remarks>Both arrays must be matrices. The matrix will be multiplied only
        /// if dimensions match accordingly. Therefore B's number of rows must
        /// equal A's number of columns. An Exception will be thrown otherwise.
        /// The multiplication will carried out on BLAS libraries, if availiable and the
        /// storage memory structure meets BLAS's requirements. If not it will be done inside .NET's
        /// framework 'by hand'. This is especially true for referencing storages with
        /// irregular dimensions. However, even GEMM on those reference storages linking into
        /// a physical storage can (an will) be carried out via BLAS dll's, if the spacing
        /// into dimensions matches the requirements of BLAS. Those are:
        /// <list>
        /// <item>the elements of one dimension will be adjecently layed out, and</item>
        /// <item>the elements of the second dimension must be regular (evenly) spaced</item>
        /// </list>
        /// <para>For reference arrays where the spacing between adjecent elements do not meet the
        /// requirements above, the matrix multiplication will be made without optimization and
        /// therefore suffer from low performance in relation to solid arrays. See <a href="http://ilnumerics.net?site=5142">online documentation: referencing for ILNumerics.Net</a></para>
        /// </remarks>
        /// <exception cref="ILNumerics.Exceptions.ILArgumentSizeException">if at least one arrays is not a matrix</exception>
        /// <exception cref="ILNumerics.Exceptions.ILDimensionMismatchException">if the size of both matrices do not match</exception>
        public static /*!HC:outCls1*/ ILArray <double> multiply(/*!HC:inCls1*/ ILArray <double> A, /*!HC:inCls2*/ ILArray <double> B)
        {
            /*!HC:outCls1*/ ILArray <double> ret = null;

            if (A.Dimensions.NumberOfDimensions != 2 ||
                B.Dimensions.NumberOfDimensions != 2)
            {
                throw new ILArgumentSizeException("Matrix multiply: arguments must be 2-d.");
            }
            if (A.Dimensions[1] != B.Dimensions[0])
            {
                throw new ILDimensionMismatchException("Matrix multiply: inner matrix dimensions must match.");
            }
            // decide wich method to use
            // test auf Regelmigkeit der Dimensionen
            int  spacingA0;
            int  spacingA1;
            int  spacingB0;
            int  spacingB1;
            char transA, transB;

            /*!HC:inArr1*/ double [] retArr = null;
            isSuitableForLapack(A, B, out spacingA0, out spacingA1, out spacingB0, out spacingB1, out transA, out transB);
            if (A.m_dimensions.NumberOfElements > ILAtlasMinimumElementSize ||
                B.m_dimensions.NumberOfElements > ILAtlasMinimumElementSize)
            {
                // do BLAS GEMM
                retArr = new /*!HC:inArr1*/ double [A.m_dimensions[0] * B.m_dimensions[1]];
                if (((spacingA0 == 1 && spacingA1 > int.MinValue) || (spacingA1 == 1 && spacingA0 > int.MinValue)) &&
                    ((spacingB0 == 1 && spacingB1 > int.MinValue) || (spacingB1 == 1 && spacingB0 > int.MinValue)))
                {
                    ret = new /*!HC:outCls1*/ ILArray <double> (retArr, new ILDimension(A.m_dimensions[0], B.m_dimensions[1]));
                    if (transA == 't')
                    {
                        spacingA1 = spacingA0;
                    }
                    if (transB == 't')
                    {
                        spacingB1 = spacingB0;
                    }
                    unsafe
                    {
                        fixed(/*!HC:outArr1*/ double *ptrC = retArr)
                        fixed(/*!HC:inArr1*/ double *pA = A.m_data)
                        fixed(/*!HC:inArr2*/ double *pB = B.m_data)
                        {
                            /*!HC:inArr1*/ double *ptrA = pA + A.getBaseIndex(0);
                            /*!HC:inArr2*/ double *ptrB = pB + B.getBaseIndex(0);

                            if (transA == 't')
                            {
                                spacingA1 = spacingA0;
                            }
                            if (transB == 't')
                            {
                                spacingB1 = spacingB0;
                            }
                            /*!HC:lapackfunc*/ Lapack.dgemm(transA, transB, A.m_dimensions[0], B.m_dimensions[1],
                                                            A.m_dimensions[1], (/*!HC:inArr1*/ double )1.0, (IntPtr)ptrA, spacingA1,
                                                            (IntPtr)ptrB, spacingB1, (/*!HC:inArr1*/ double )1.0, retArr, A.m_dimensions[0]);
                        }
                    }
                    return(ret);
                }
            }
            // do GEMM by hand
            retArr = new /*!HC:outArr1*/ double [A.m_dimensions[0] * B.m_dimensions[1]];
            ret    = new /*!HC:outCls1*/ ILArray <double> (retArr, A.m_dimensions[0], B.m_dimensions[1]);
            unsafe {
                int in2Len1 = B.m_dimensions[1];
                int in1Len0 = A.m_dimensions[0];
                int in1Len1 = A.m_dimensions[1];
                fixed(/*!HC:outArr1*/ double *ptrC = retArr)
                {
                    /*!HC:outArr1*/ double *pC = ptrC;

                    for (int c = 0; c < in2Len1; c++)
                    {
                        for (int r = 0; r < in1Len0; r++)
                        {
                            for (int n = 0; n < in1Len1; n++)
                            {
                                *pC += A.GetValue(r, n) * B.GetValue(n, c);
                            }
                            pC++;
                        }
                    }
                }
            }
            return(ret);
        }
Exemplo n.º 25
0
 public static extern IppStatus ippsRound_64f(double *pSrc, double *pDst, int len);
Exemplo n.º 26
0
 public static extern void GetRXAAGCThresh(int channel, double *thresh, double size, double rate);
Exemplo n.º 27
0
 public static extern IppStatus ippsTone_64f(double *pDst, int len, double magn, double rFreq, double *pPhase, IppHintAlgorithm hint);
Exemplo n.º 28
0
 public static extern void SetEXTDIVRotate(int id, int nr, double *Irotate, double *Qrotate);
Exemplo n.º 29
0
 public static extern IppStatus ippsNearbyInt_64f(double *pSrc, double *pDst, int len);
		/// <summary>
		/// Creates a new CudaRegisteredHostMemory_double from an existing IntPtr. IntPtr must be page size aligned (4KBytes)!
		/// </summary>
		/// <param name="hostPointer">must be page size aligned (4KBytes)</param>
		/// <param name="size">In elements</param>
		public CudaRegisteredHostMemory_double(IntPtr hostPointer, SizeT size)
		{
			_intPtr = hostPointer;
			_size = size;
			_typeSize = (SizeT)Marshal.SizeOf(typeof(double));
			_ptr = (double*)_intPtr;
		}
Exemplo n.º 31
0
 public static extern IppStatus ippsTriangle_64f(double *pDst, int len, double magn, double rFreq, double asym, double *pPhase);
        /// <summary>
        /// Solves the specified model.
        /// </summary>
        /// <param name="model">The model.</param>
        /// <param name="variableValues">The variable values.</param>
        /// <returns>A solution object.</returns>
        public Solution Solve(Model model, IDictionary<string, double> variableValues = null)
        {
            if (model == null)
                throw new ArgumentNullException("model");
            if (IsBusy)
                throw new InvalidOperationException("solver is busy");
            try
            {
                IsBusy = true;
                if (variableValues == null)
                    variableValues = new Dictionary<string, double>();

                // Time measurement
                DateTime overallWallTimeStart = DateTime.Now;

                // Store the indices used by GLPK to map the solution
                Dictionary<IVariable, int> variablesToIdx = new Dictionary<IVariable, int>();

                // Create an empty GLPK model
                _model = model;
                _glpk_model = glp_create_prob();

                glp_set_prob_name(_glpk_model, model.Name);
                WriteLogLine(" - Creating GLPK model");
                // Create internal GLPK variables from model's variable list
                WriteLogLine(" - Creating GLPK variables");
                int colIndex = glp_add_cols(_glpk_model, model.VariablesCount); // returns first column index
                foreach (IVariable variable in model.Variables)
                {
                    if (variable.Type != VariableType.Continuous)
                        this.IsMixedIntegerModel = true;
                    //throw new ArgumentException("MIPs/ IPs not supported yet");

                    // Check for fixed variables
                    if (variableValues.ContainsKey(variable.Name))
                    {
                        variable.LowerBound = variableValues[variable.Name];
                        variable.UpperBound = variableValues[variable.Name];
                    }

                    // Map variables bound types to GLPK's internal structures
                    GLP_ROWTYPE glpkType;
                    if (double.IsNegativeInfinity(variable.LowerBound) && double.IsPositiveInfinity(variable.UpperBound))
                        glpkType = GLP_ROWTYPE.GLP_FR;
                    else if (!double.IsNegativeInfinity(variable.LowerBound) &&
                             double.IsPositiveInfinity(variable.UpperBound))
                        glpkType = GLP_ROWTYPE.GLP_LO;
                    else if (double.IsNegativeInfinity(variable.LowerBound) &&
                             !double.IsPositiveInfinity(variable.UpperBound))
                        glpkType = GLP_ROWTYPE.GLP_UP;
                    else if (variable.LowerBound == variable.UpperBound)
                        glpkType = GLP_ROWTYPE.GLP_FX;
                    else
                        glpkType = GLP_ROWTYPE.GLP_DB;

                    // Set bound type and bounding values; depending on the type bounds might be ignored by GLPK
                    glp_set_col_bnds(_glpk_model, colIndex, (int)glpkType, variable.LowerBound, variable.UpperBound);

                    // Set the variable's name
                    glp_set_col_name(_glpk_model, colIndex, variable.Name);

                    // Set the variable's kind
                    switch (variable.Type)
                    {
                        case VariableType.Continuous:
                            glp_set_col_kind(_glpk_model, colIndex, (int)GLP_VARIABLE_KIND.GLP_CV);
                            break;
                        case VariableType.Integer:
                            if (variable.UpperBound == 1 && variable.LowerBound == 0)
                                glp_set_col_kind(_glpk_model, colIndex, (int)GLP_VARIABLE_KIND.GLP_BV);
                            else
                                glp_set_col_kind(_glpk_model, colIndex, (int)GLP_VARIABLE_KIND.GLP_IV);
                            break;
                        default:
                            throw new NotImplementedException("Variable type not supported by OptimizationFramework");
                            break;
                    }

                    // Store the used index for later activity mapping
                    variablesToIdx.Add(variable, colIndex);

                    colIndex++;
                }

                // Create internal GLPK objective function
                WriteLogLine(" - Creating GLPK objective function");
                if (model.ObjectivesCount != 0)
                {
                    if (model.ObjectivesCount > 1)
                        throw new ArgumentException("Only one objective supported");

                    var objective = model.Objectives.ElementAt(0);

                    // Loop through all expressions and set the variable's coefficient
                    foreach (var term in objective.Expression.Terms)
                    {
                        if (!term.isLinear)
                            throw new ArgumentException("Only linear terms in objective allowed: " + term);
                        glp_set_obj_coef(_glpk_model, variablesToIdx[term.Variable], term.Factor);
                    }

                    // Set objective's name
                    glp_set_obj_name(_glpk_model, objective.Name);

                    // Set GLPKs objective type
                    if (objective.Sense == ObjectiveSense.Maximize)
                        glp_set_obj_dir(_glpk_model, (int)OBJECTIVE_TYPE.GLP_MAX);
                    else
                        glp_set_obj_dir(_glpk_model, (int)OBJECTIVE_TYPE.GLP_MIN);
                }

                // Create GLPK constraints and reserve space for all of them
                WriteLogLine(" - Creating GLPK constraints");
                int rowIndex = glp_add_rows(_glpk_model, model.ConstraintsCount); // Returns the first rowIndex
                // Dummy constraint since GLPKs arrays start from 1
                ia.Add(-1);
                ja.Add(-1);
                ar.Add(-1d);

                // Loop through all constraints in the model
                foreach (var constraint in model.Constraints)
                {
                    // Loop through each term
                    foreach (var term in constraint.Expression.Terms)
                    {
                        // Add coefficient (factor) for matrix cell [i,j], i=rowIndex, j=variablesToIdx[term.Variable]
                        ia.Add(rowIndex);
                        ja.Add(variablesToIdx[term.Variable]);
                        ar.Add(term.Factor);
                    }

                    // Map constraint bound types to GLPK's internal structures
                    GLP_ROWTYPE glpkConstraintType;
                    if (double.IsNegativeInfinity(constraint.LowerBound) &&
                        double.IsPositiveInfinity(constraint.UpperBound))
                        glpkConstraintType = GLP_ROWTYPE.GLP_FR;
                    else if (!double.IsNegativeInfinity(constraint.LowerBound) &&
                             double.IsPositiveInfinity(constraint.UpperBound))
                        glpkConstraintType = GLP_ROWTYPE.GLP_LO;
                    else if (double.IsNegativeInfinity(constraint.LowerBound) &&
                             !double.IsPositiveInfinity(constraint.UpperBound))
                        glpkConstraintType = GLP_ROWTYPE.GLP_UP;
                    else if (constraint.LowerBound == constraint.UpperBound)
                        glpkConstraintType = GLP_ROWTYPE.GLP_FX;
                    else
                        glpkConstraintType = GLP_ROWTYPE.GLP_DB;

                    // Since the OF moves LBs/ UBs to constant terms and sets the constraint's bound to 0, 
                    // we have to add the constant to the bound again
                    var ub = constraint.UpperBound;
                    var lb = constraint.LowerBound;
                    if (constraint.Expression.Constant != 0)
                    {
                        if (ub != double.PositiveInfinity)
                            ub -= constraint.Expression.Constant;
                        if (lb != double.NegativeInfinity)
                            lb -= constraint.Expression.Constant;
                    }

                    // Set bounds for the constraint
                    glp_set_row_bnds(_glpk_model, rowIndex, (int)glpkConstraintType, lb,
                                     ub);
                    glp_set_row_name(_glpk_model, rowIndex, constraint.Name);
                    rowIndex++;
                }

                // Solve actual problem
                ModelStatus modelStatus;
                SolutionStatus solutionStatus;

                // Print some logging data
                WriteLogLine(String.Format(" - Model has {0} variables", model.VariablesCount));
                WriteLogLine(String.Format(" - Model has {0} integer variables", model.Variables.Where(v => v.Type == VariableType.Integer).Count()));
                WriteLogLine(String.Format(" - Model has {0} constraints", model.ConstraintsCount));
                WriteLogLine(String.Format(" - Model has {0} non zero elements", ia.Count));

                //// Try to write MPS file
                //if (Directory.Exists(sDebugDirectory))
                //{
                //    try
                //    {
                //        glp_write_lp(_glpk_model, null, sDebugDirectory + model.Name + ".lp");
                //        glp_write_mps(_glpk_model, (int)MPS_FILETYPE.GLP_MPS_FILE, null,
                //                     sDebugDirectory + model.Name + ".mps");
                //        WriteLogLine(" - Saved models in " + sDebugDirectory);
                //    }
                //    catch (Exception e)
                //    {
                //        WriteLogLine("ERROR: Could not write model files: " + e.Message);
                //    }
                //}

                WriteLogLine(" - Solving GLPK model");
                bool returnValue = SolveProblem(_glpk_model, ia, ja, ar);

                DateTime overallWallTimeEnd = DateTime.Now;
                TimeSpan overallWallTime = overallWallTimeEnd - overallWallTimeStart;

                // Set Optimization.Framework's solution status based on the GLPK structures
                GLP_SOLUTIONSTATUS status;
                if (this.IsMixedIntegerModel)
                    status = (GLP_SOLUTIONSTATUS)glp_mip_status(_glpk_model);
                else
                    status = (GLP_SOLUTIONSTATUS)glp_get_status(_glpk_model);

                switch (status)
                {
                    case GLP_SOLUTIONSTATUS.GLP_NOFEAS:
                    case GLP_SOLUTIONSTATUS.GLP_INFEAS:
                        solutionStatus = SolutionStatus.NoSolutionValues;
                        modelStatus = ModelStatus.Infeasible;
                        break;
                    case GLP_SOLUTIONSTATUS.GLP_UNBND:
                        solutionStatus = SolutionStatus.NoSolutionValues;
                        modelStatus = ModelStatus.Unbounded;
                        break;
                    case GLP_SOLUTIONSTATUS.GLP_FEAS:
                    case GLP_SOLUTIONSTATUS.GLP_OPT:
                        solutionStatus = SolutionStatus.Optimal;
                        modelStatus = ModelStatus.Feasible;
                        break;
                    default:
                        solutionStatus = SolutionStatus.NoSolutionValues;
                        modelStatus = ModelStatus.Unknown;
                        break;
                }

                //Set the objective and variables' activities
                Dictionary<string, double> objValues = null;
                Dictionary<string, double> varValues = null;
                if (solutionStatus != SolutionStatus.NoSolutionValues)
                {
                    objValues = new Dictionary<string, double>();
                    if (model.ObjectivesCount != 0)
                    {
                        objValues.Add(model.Objectives.Single().Name,
                            (this.IsMixedIntegerModel ? glp_mip_obj_val(_glpk_model) : glp_get_obj_val(_glpk_model)));
                    }

                    varValues = new Dictionary<string, double>();
                    foreach (var variableKey in variablesToIdx)
                    {
                        double value = -1;

                        if (this.IsMixedIntegerModel)
                            value = glp_mip_col_val(_glpk_model, variablesToIdx[variableKey.Key]);
                        else
                            value = glp_get_col_prim(_glpk_model, variablesToIdx[variableKey.Key]);

                        varValues.Add(variableKey.Key.Name, value);
                    }

                    //// Write solution values
                    //if (Directory.Exists(sDebugDirectory))
                    //{
                    //    try
                    //    {
                    //        System.IO.StreamWriter file = new System.IO.StreamWriter(sDebugDirectory + "solution.txt");

                    //        foreach(var kvp in varValues.OrderBy(kvp => kvp.Key))
                    //            file.WriteLine(kvp.Key + "\t\t\t"+ kvp.Value);

                    //        file.Close();
                    //    } 
                    //    catch (Exception e)
                    //    {
                    //        WriteLogLine("Fehler beim Schreiben der Solverlösung im Debug-Modus:" + e.Message);
                    //    }
                    //}
                }

                // Create a new Optimization.Framework solution object and return it
                var solution = new Solution(model.Name, overallWallTime, modelStatus,
                                            solutionStatus,
                                            varValues, null, objValues);

                return solution;
            }
            catch (Exception exception)
            {
                Console.WriteLine(exception.Message);
            }
            finally
            {
                IsBusy = false;
            }

            return null;
        }
Exemplo n.º 33
0
 public static extern IppStatus ippsFFTFwd_RToPack_64f(double *pSrc, double *pDst, IppsFFTSpec_R_64f *pFFTSpec, byte *pBuffer);
Exemplo n.º 34
0
        public unsafe Matrix(double[] data, int rows, int columns)
        {
            if (rows < 1) throw new ArgumentException("rows must > 0");
            if (columns < 1) throw new ArgumentException("columns must > 0");
            if (data.Length != rows * columns) throw new ArgumentException("data != rows * columns");

            _rowCount = rows;
            _columnCount = columns;
            _length = _rowCount * _columnCount;
            Data = (double*)Marshal.AllocHGlobal(_rowCount * _columnCount * sizeof(double));
            for (int r = 0; r < _rowCount; r++)
            {
                int cStart = r * columns;
                for (int c = 0; c < _columnCount; c++)
                {
                    this[r, c] = data[cStart + c];
                }
            }
        }
Exemplo n.º 35
0
 public static extern IppStatus ippsFlip_64f_I(double *pSrcDst, int len);
Exemplo n.º 36
0
 public unsafe Matrix(int rows, int columns = 1, Boolean fillWidthZero = true)
 {
     if (rows < 1) throw new ArgumentException("rows must > 0");
     if (columns < 1) throw new ArgumentException("columns must > 0");
     _rowCount = rows;
     _columnCount = columns;
     _length = _rowCount * _columnCount;
     Data = (double*)Marshal.AllocHGlobal(_rowCount * _columnCount * sizeof(double));
     if (fillWidthZero == true)
     {
         Fill(0);
     }
 }
Exemplo n.º 37
0
 public static unsafe void GetSource(int source, SourceDouble param, double *values) => _GetSourcedvPtr(source, param, values);