grade_blending_constraints

PURPOSE ^

Constructs the grade blending constraint matrix

SYNOPSIS ^

function [A_grade b_Ugrade] = grade_blending_constraints(Blocks,numBlocks,numCuts,numOfPeriods,numOfElements,varargin)

DESCRIPTION ^

 Constructs the grade blending constraint matrix
--------------------------------------------------------------------------
 Updated May 27, 2009
 Date: Aug 06, 2008, ver01
 % By: Hooman Askari
--------------------------------------------------------------------------
Inputs 
       Blocks:
           a struct containing Blocks(numBlocks) elements with the field
           correspoiding to the input file format.
       numBlocks: 
            a 1*1 vector containing the total number of blocks  
       numOfPeriods:
            a 1*1 vector containing the number of periods  
       numOfElements:
            a 1*1 vector containing the number of Elements  
       varargin: variable number of input arguments 
                 holding the min and max average grade allowed for each 
                 element. 
       in this case: oreGradeMin, oreGradeMax, sGradeMin, sGradeMax, 
       pGradeMin, pGradeMax:
            a 1*1 vector containing the min and max grade for each element
            that are allowed to be sent to the processing plant 
--------------------------------------------------------------------------
   
--------------------------------------------------------------------------
 outputs
         construct an A_grade matrix using 
          A_grade = [sparse(m, numCuts * numOfPeriods )...
                     A_grade... 
                    sparse(m, numCuts * numOfPeriods)];
       
       b_Ugrade = grade boundary conditions 
--------------------------------------------------------------------------

--------------------------------------------------------------------------

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 % Constructs the grade blending constraint matrix
0002 %--------------------------------------------------------------------------
0003 % Updated May 27, 2009
0004 % Date: Aug 06, 2008, ver01
0005 % % By: Hooman Askari
0006 %--------------------------------------------------------------------------
0007 %Inputs
0008 %       Blocks:
0009 %           a struct containing Blocks(numBlocks) elements with the field
0010 %           correspoiding to the input file format.
0011 %       numBlocks:
0012 %            a 1*1 vector containing the total number of blocks
0013 %       numOfPeriods:
0014 %            a 1*1 vector containing the number of periods
0015 %       numOfElements:
0016 %            a 1*1 vector containing the number of Elements
0017 %       varargin: variable number of input arguments
0018 %                 holding the min and max average grade allowed for each
0019 %                 element.
0020 %       in this case: oreGradeMin, oreGradeMax, sGradeMin, sGradeMax,
0021 %       pGradeMin, pGradeMax:
0022 %            a 1*1 vector containing the min and max grade for each element
0023 %            that are allowed to be sent to the processing plant
0024 %--------------------------------------------------------------------------
0025 %
0026 %--------------------------------------------------------------------------
0027 % outputs
0028 %         construct an A_grade matrix using
0029 %          A_grade = [sparse(m, numCuts * numOfPeriods )...
0030 %                     A_grade...
0031 %                    sparse(m, numCuts * numOfPeriods)];
0032 %
0033 %       b_Ugrade = grade boundary conditions
0034 %--------------------------------------------------------------------------
0035 %
0036 %--------------------------------------------------------------------------
0037 
0038 function [A_grade b_Ugrade] =  grade_blending_constraints(Blocks,...
0039                                                           numBlocks,...
0040                                                           numCuts,...
0041                                                           numOfPeriods,...
0042                                                           numOfElements,...
0043                                                           varargin)
0044 
0045 % varargin is a cell array, a special kind of MATLAB array that consists of
0046 % cells instead of array elements
0047                                                             
0048    % unpacking varargin
0049    % unpacks the minimum and maximum element grades into two arrays
0050    % elementsMin (1, 1:numberOfElements) = element's minimum grade
0051    % elementsMax (1, 1:numberOfElements) = element's maximum grade
0052    % the matrix column index corrosponds to the element index
0053    % example: second element maximum is in  elementsMax(1,2)
0054    iMin = 1;
0055    iMax = 1;
0056    for k = 1:length(varargin);
0057         % check to see if the index of varargin is odd
0058         % add the variable to the elementsMin
0059         % other wise add it to the elementsMax
0060         if rem(k,2)~= 0
0061             if isempty(varargin{1,k})
0062                 elementsMin(1, iMin) = NaN;
0063             else
0064                 elementsMin(1, iMin) = varargin{1,k};
0065             end
0066             iMin = iMin + 1;
0067         else
0068             if isempty(varargin{1,k})
0069                 elementsMax(1, iMax) = NaN;
0070             else
0071                 elementsMax(1, iMax) = varargin{1,k};
0072             end
0073             iMax = iMax + 1;
0074         end
0075    end 
0076   
0077    % vectors containing the relevant elements
0078    oreTonnage = [Blocks.OreTonnes]';
0079    sTonnage = [Blocks.S]'/100;
0080    pTonnage = [Blocks.P]'/100;
0081    
0082    % elementsTonnage(numberOfElments, numBlocks)
0083    elementsTonnage = [oreTonnage'; sTonnage'; pTonnage'];
0084    
0085    % new version make sure you change to this after fixing the problem
0086    oreGrade = [Blocks.gradeMWT]';
0087    sGrade = [Blocks.gradeS]';
0088    pGrade = [Blocks.gradeP]';
0089 
0090    elementsGrade = [oreGrade'; sGrade'; pGrade'];
0091     
0092    % initialize the A_grade vector
0093    A_grade =[];
0094     
0095    for iElements = 1 : numOfElements
0096        
0097        %unequality constraints for elements number iElements minimum
0098        if ~isnan (elementsMin(iElements))
0099            % .* = an element by element multiplication
0100            
0101            % minMWTVector =(oreGradeVector-oreGradeMinValue).* ...
0102            % oreTonnageVector.*-1;
0103            minVector =...
0104                (elementsGrade(iElements,:)- elementsMin(iElements))...
0105                .* elementsTonnage(iElements,:).*-1;
0106           
0107            A_grade = update_constraints(A_grade,...
0108                                         numBlocks,...
0109                                         numOfPeriods,...
0110                                         minVector);
0111        end
0112 
0113        %unequality constraints for elements number iElements maximum
0114        if ~isnan (elementsMax(iElements))
0115            
0116            % maxMWTVector =(oreGradeVector-oreGradeMaxValue).*...
0117            % oreTonnageVector;
0118            maxVector =...
0119                (elementsGrade(iElements,:)- elementsMax(iElements))...
0120                .* elementsTonnage(iElements,:);
0121            
0122            A_grade = update_constraints(A_grade,...
0123                                         numBlocks,...
0124                                         numOfPeriods,...
0125                                         maxVector);
0126        end
0127        
0128    end % for iElements
0129    
0130    [m n] = size(A_grade);
0131    b_Ugrade =  zeros(m,1); 
0132    
0133    % convert to a sparse matrix
0134    A_grade = sparse(A_grade);
0135    b_Ugrade = sparse(b_Ugrade);
0136    
0137    % the mulitplier vector in the constraints matrix have different sizes
0138    % and units. (some are tonnage some are grade....). It is necessary to
0139    % transform the constraints matrix in a way that it unit less to be
0140    % solved by the MIP code.
0141    
0142    % divide each row vector by its norm [A(i,:)* A(i,:)']^1/2
0143    % A_gradeNormVector(m,1) is vertical vector holding the respective norm
0144    % of each row of the A_grade matrix
0145    
0146    % try to vectorize this section
0147    
0148    for i = 1:m  
0149       A_gradeNormVector(i,1) = norm(A_grade(i,:));     
0150    end
0151    
0152    for i = 1:m  
0153       normA = A_gradeNormVector(i,1); 
0154       A_grade(i,:) = A_grade(i,:)/normA;     
0155    end
0156    
0157    % b_Ugrade is all zero so doesn't need normalizing in cases where b_U
0158    % and b_L have values greater than zero they need to be normailized as
0159    % well.
0160    
0161    % construct an A_grade matrix using
0162    A_grade = [sparse(m, numCuts * numOfPeriods )...
0163               A_grade... 
0164               sparse(m, numCuts * numOfPeriods)];
0165          
0166 end
0167 
0168 
0169   
0170     
0171 
0172

Generated on Wed 08-Jul-2009 18:57:55 by m2html © 2003