slope_constraints

PURPOSE ^

Constructs the slope constraints

SYNOPSIS ^

function [A_slope b_Uslope] = slope_constraints( blocksOnTopCellArray,numBlocks,numOfPeriods)

DESCRIPTION ^

 Constructs the slope constraints 
--------------------------------------------------------------------------
 Date: Nov. 19, 2008, ver01
 By: Hooman Askari
--------------------------------------------------------------------------
Inputs 
--------------------------------------------------------------------------
   blocksOnTopCellArray:
   numBlocks:
   numOfPeriods:   

--------------------------------------------------------------------------
 outputs
       A_slope: 
       b_Uslope:
       
--------------------------------------------------------------------------
   
--------------------------------------------------------------------------
 Pseudo Code
   
--------------------------------------------------------------------------

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 % Constructs the slope constraints
0002 %--------------------------------------------------------------------------
0003 % Date: Nov. 19, 2008, ver01
0004 % By: Hooman Askari
0005 %--------------------------------------------------------------------------
0006 %Inputs
0007 %--------------------------------------------------------------------------
0008 %   blocksOnTopCellArray:
0009 %   numBlocks:
0010 %   numOfPeriods:
0011 %
0012 %--------------------------------------------------------------------------
0013 % outputs
0014 %       A_slope:
0015 %       b_Uslope:
0016 %
0017 %--------------------------------------------------------------------------
0018 %
0019 %--------------------------------------------------------------------------
0020 % Pseudo Code
0021 %
0022 %--------------------------------------------------------------------------
0023 function [A_slope b_Uslope] = slope_constraints( blocksOnTopCellArray,...
0024                                                  numBlocks,...
0025                                                  numOfPeriods)                                                
0026    yA_slope = cell(numBlocks,1);     
0027    xA_slope = cell(numBlocks,1);  
0028    yA=[]; save yA yA; 
0029    xA=[]; save xA xA;   
0030     
0031    % a blank template to preallocate memory space to the yVector
0032    % and xVector
0033    blankTemp = sparse(1, numBlocks);      
0034    index = 0;
0035         
0036     for iBlocks = 1 : numBlocks
0037         
0038        if length(find(blocksOnTopCellArray{iBlocks})) ~= 0
0039             
0040            % blocksOnTop is a (1*numOfBlocksOnTop) matrix holding the
0041            % indices of the blocks on top of the current block iBlocks
0042            [row col blocksOnTop] = find(blocksOnTopCellArray{iBlocks}); 
0043 
0044            for j = 1:length(blocksOnTop)
0045            
0046                % one constraint per block per period.
0047                % the number of constraints for each block is equal to the
0048                % number of periods
0049 
0050                % create the diagonal matrix, see documentation
0051                %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0052                xVec = blankTemp;
0053                xVec(1, iBlocks)= 1;
0054 
0055                % create the diagMatrix
0056                A = cell(1, numOfPeriods);
0057                [A{:}] = deal(xVec);
0058                xMatrix = blkdiag(A{:});
0059 
0060                % create the lower triangular matrix see documentation
0061                %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0062                yVec = blankTemp; 
0063                yVec(1, blocksOnTop(j))= -1; 
0064 
0065                % the case that all the blocks on top are added
0066                % need to re-adjust the for loop, omit the loop
0067                % for j = 1:length(blocksOnTop)
0068 
0069                % yVec(1, blocksOnTop(1:end))= -1;
0070 
0071                yMatrixCell = cell(numOfPeriods,numOfPeriods);
0072                [yMatrixCell{:}] = deal(blankTemp);
0073 
0074                for i = 1:numOfPeriods
0075                    [yMatrixCell{i,1:(i)}] = deal(yVec);    
0076                end 
0077 
0078                yMatrix = cell2mat(yMatrixCell);
0079                yMatrix = sparse(yMatrix);
0080 
0081                index = index + 1;
0082                yA_slope{index,1}= deal(yMatrix);
0083                xA_slope{index,1}= deal(xMatrix);
0084                               
0085                % the number controls how often the yA and xA array are
0086                % supposed to be written into file
0087                
0088                if index >= 2000
0089                    load yA; load xA;                   
0090                    yA =[yA; cell2mat(yA_slope)];
0091                    xA =[xA; cell2mat(xA_slope)];
0092                    save yA yA; save xA xA;
0093                    clear yA yA_slope xA xA_slope;  
0094                    index = 0;
0095                end 
0096                                           
0097                clear xMatrix yMatrix yVec xVec;
0098            
0099            end % for j = 1:length(blocksOnTop)
0100                                           
0101            iBlocks;
0102                                      
0103       end % if numOfBlocksOnTop(iBlocks) ~= 0
0104            
0105     end % end for iBlocks
0106     
0107    % check to see if the size of the matirx is greater than 1
0108    
0109    % the mulitplier vector in the constraints matrix have different sizes
0110    % and units. (some are tonnage some are grade....). It is necessary to
0111    % transform the constraints matrix in a way that it is unit less to be
0112    % solved by the MIP code.
0113    
0114    % divide each row vector by its norm [A(i,:)* A(i,:)']^1/2
0115    % A_slope2NormVector(m,1) is vertical vector holding the respective
0116    % norm of each row of the A_slope2 matrix
0117    
0118    % if there is any yA-slope not written to yA. it is going to be taken
0119    % care of here
0120    load yA; load xA;
0121    yA =[yA; cell2mat(yA_slope)];
0122    xA =[xA; cell2mat(xA_slope)];
0123    save yA yA; save xA xA;
0124    %xA = full(xA);
0125    %yA = full(yA);
0126    clear yA xA yA_slope xA_slope;
0127    
0128    load yA; load xA
0129    [m n] = size(yA);
0130    b_Uslope =  sparse(m,1); 
0131    
0132    % A_slope = [yA xA sparse(m, 2*n)];
0133    A_slope = [xA                                    sparse(m, numBlocks*numOfPeriods)...
0134               sparse(m, numBlocks*numOfPeriods)     yA...
0135               sparse(m, numOfPeriods)               sparse(m, numOfPeriods)...
0136               sparse(m, numOfPeriods)               sparse(m, numOfPeriods)];
0137    
0138     save A_slope A_slope            
0139 end

Generated on Fri 30-Jul-2010 16:56:05 by m2html © 2003