


Constructs the slope constraints
--------------------------------------------------------------------------
Updated May 27, 2009
Date: Nov. 19, 2008, ver01
By: Hooman Askari
--------------------------------------------------------------------------
Inputs
--------------------------------------------------------------------------
blocksOnTopCellArray:
numBlocks:
numOfPeriods:
--------------------------------------------------------------------------
outputs
A_slope:
b_Uslope:
--------------------------------------------------------------------------
--------------------------------------------------------------------------
Pseudo Code
--------------------------------------------------------------------------

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