slope2_constraints

PURPOSE ^

Constructs the slope constraints

SYNOPSIS ^

function [A_slope2 b_Uslope2] = slope2_constraints(numBlocks,numOfPeriods)

DESCRIPTION ^

 Constructs the slope constraints 
--------------------------------------------------------------------------
 Updated May 27, 2009
 Date: Nov. 19, 2008, ver01
 By: Hooman Askari

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 % Constructs the slope constraints
0002 %--------------------------------------------------------------------------
0003 % Updated May 27, 2009
0004 % Date: Nov. 19, 2008, ver01
0005 % By: Hooman Askari
0006 function [A_slope2 b_Uslope2] = slope2_constraints(numBlocks,...
0007                                                    numOfPeriods)                                         
0008                                                
0009    yA_slope = cell(numBlocks,1);     
0010    xA_slope = cell(numBlocks,1);     
0011     
0012    % a blank template to preallocate memory space to the yVector
0013    % and xVector
0014    blankTemp = sparse(1, numBlocks); 
0015    yA=[]; save yA yA; 
0016    xA=[]; save xA xA;   
0017    xT=[]; save xT xT;   
0018    index = 0;
0019         
0020     for iBlocks = 1 : numBlocks
0021         
0022            % create the lower triangular matrix see documentation
0023            %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0024            yVec = blankTemp; 
0025            yVec(1, iBlocks)= 1; 
0026            
0027            yMatrixCell = cell(numOfPeriods,numOfPeriods);
0028            [yMatrixCell{:}] = deal(blankTemp);
0029 
0030            for i = 1:numOfPeriods
0031                [yMatrixCell{i,1:(i)}] = deal(yVec);    
0032            end 
0033                       
0034            yMatrix = cell2mat(yMatrixCell);
0035            yMatrix = sparse(yMatrix);
0036            
0037            % create the diagonal matrix, see documentation
0038            %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0039            xVec = blankTemp;
0040            xVec(1, iBlocks)= -1;
0041            
0042            % create the diagMatrix
0043            A = cell(1, numOfPeriods);
0044            [A{:}] = deal(xVec);
0045            xMatrix = blkdiag(A{:});
0046                     
0047            yA_slope{iBlocks,1}= deal(yMatrix);
0048            xA_slope{iBlocks,1}= deal(xMatrix);
0049            
0050            clear xMatrix yMatrix yVec xVec;
0051            %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0052            % x in the current period T
0053            xT_Ivec = blankTemp;
0054            % x in the period T+1
0055            xT_IIvec = blankTemp;
0056 
0057            xT_Ivec(1, iBlocks)= 1;
0058            xT_IIvec(1, iBlocks)= - 1;
0059            
0060            B = cell(1, numOfPeriods);
0061            [B{:}] = deal(xT_Ivec);
0062            xT_I_MatrixCell = blkdiag(B{:});
0063            
0064            xT_II_MatrixCell = cell(numOfPeriods-1,numOfPeriods);
0065            [xT_II_MatrixCell{:}] = deal(blankTemp);
0066                       
0067            for i = 1:numOfPeriods-1
0068                [xT_II_MatrixCell{i,i+1}] = deal(xT_IIvec);    
0069            end 
0070            
0071            xT_II_MatrixCell = cell2mat(xT_II_MatrixCell);
0072            
0073            xT_Matrix = xT_I_MatrixCell(1:end-1,:) + xT_II_MatrixCell;
0074            
0075            xT_slope{iBlocks,1}= deal(xT_Matrix);
0076            
0077            clear xT_I_MatrixCell xT_II_MatrixCell xT_Matrix
0078            
0079            iBlocks
0080            
0081           % saves the large xT matrices to a file
0082           % revise this the counter here is index and in xT is iBlocks
0083           index = index + 1; 
0084           if index >= 2000
0085                load yA; 
0086                yA =[yA; cell2mat(yA_slope)];
0087                save yA yA;
0088                clear yA yA_slope
0089 
0090                load xA; 
0091                xA =[xA; cell2mat(xA_slope)];
0092                save xA xA;
0093                clear xA xA_slope
0094                
0095                load xT;
0096                xT =[xT; cell2mat(xT_slope)];
0097                save xT xT
0098                clear xT_slope xT;              
0099                
0100                index = 0;
0101           end 
0102           
0103 end % iBlocks = 1 : numBlocks
0104 % check to see if the size of the matirx is greater than 1
0105    
0106  pack;
0107   
0108  load yA; load xA; load xT;
0109  yA =[yA; cell2mat(yA_slope)];
0110  xA =[xA; cell2mat(xA_slope)];
0111  xT =[xT; cell2mat(xT_slope)];
0112  save yA yA; save xA xA; save xT xT
0113  clear yA xA yA_slope xA_slope xT_slope xT;  
0114   
0115  load yA; load xA; load xT
0116  [m n] = size(yA);
0117  [m1 n1] = size(xT);
0118  
0119 % the numBlocks used through calling this function is actually numCuts.
0120 % so the get the real number of blocks to complete the A_slope matrix we
0121 % need to reload the numBlocks into memory
0122 load inputToMILPCutsBlocks numBlocks numCuts
0123      
0124  A_slope2 = [xA  sparse(m, numBlocks*numOfPeriods)  yA;...
0125              xT  sparse(m1, numBlocks*numOfPeriods) sparse(m1, numCuts*numOfPeriods)];
0126            
0127  b_Uslope2 = sparse((m+m1),1);    
0128           
0129 end

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