• Nem Talált Eredményt

Row-wise BTRAN algorithm

Improvement techniques of pricing

3.3 Row-wise BTRAN algorithm

A more efficient BTRAN implementation can be achieved using an alternative method for storing the η vectors. Recall that only the nonzeros of these vectors and positions of nonzeros in the vectors are stored, and the number of these vectors is s. The vectors η and a have m components. Introduce an array called Lη, which contains references to mdifferent lists. Each list contains (idx,v) pairs as follows: The list j contains the ηij values from vector ηi, where ηij , 0. When these lists are constructed, the descending order of these pairs has to be maintained by indices. Fortunately, it is easy to fulfill this requirement: Creating a new ETM means that a newηvector has to be appended to the list ofηvectors, i.e. the nonzero elements of the new vectors are inserted in to the front of the lists. The insertion of a new element hasO(1) complexity. Obviously, the nonzeros of the ηsvector are at the beginning of the lists and the values ofη1 are at the end of the lists, as Figure (3.4) shows.

In the first step, the BTRAN that uses this new data structure collects the values and indices of nonzeros from the input vectora. Ifaj ,0, then the algorithm will need the first element of the linked listLη[j]. This information was collected by using an otherslength array named La, which stores linked lists. The linked list La[j] contains such pointers, which refers to the elements of linked lists stored by array Lη: When aj , 0, then the algorithm examines, which element of the currentηidoes the first element of the listLη[j]

belongs to. Namely, the lists of the arrayLarepresents thatηcomponents that have to be

Figure 3.5: Distribution of nonzero products in STOCFOR2. The number of rows is 2156

Figure 3.6: Distribution of nonzero products in TRUSS. The number of rows is 999

Figure 3.7: An example for the relationship ofLη andLa arrays

multiplied with the nonzeros ofa. The algorithm will maintain the processed elements of theLηlists. In the second step, a pointer is inserted in to the list La[i], which refers to the first element of the list Lη[j]. Figure (3.7) shows an example for this data structure:

The figure shows an example input vectora, where a2 = 2, a3 = 1 anda6 = 5. There are fourηvectors, so at first we have to multiplyaandη4. Theη4has four nonzero elements, but we only have to use theη34andη64, becausea3η34 ,0,a6η64 ,0 and any other products are zero. Therefore, we have to insert pointers toη34andη64 into the listLa.

From this data structure it can be read with which vectorηiandahave to be multiplied:

The algorithm chooses the last element of the arrayLa, which index denoted byidx. Now the listLa[idx] shows which elements ofηidxhave to be multiplied with the corresponding elements of the vectora. This ensures that the products will be nonzeros, so the algorithm does not perform unnecessary multiplications.

Denote pivotIndexthe value of pidx. The dot product gives the new value ofapivotIndex, and the algorithm decreasesidxby 1, i.e. it chooses the previous list ofLa. There are three cases whenapivotIndex will be updated:

• The value ofapivotIndex was zero, and it remains zero, or it was nonzero, and remains nonzero also. In this case, extra administration steps are unnecessary.

• If the result is not zero, but theapivotIndexwas zero before, the algorithm have to find the firstηpivotIndexj element of Lη[pivotIndex], where j is the utmost but less thanidx, and it inserts its pointer into the La[j]. Finding this element can be perform in O(log2) time, using an appropriate linked list data structure. Figure (3.9) shows this situation: Thea4increases from zero to 4.5, i.e. getsanew nonzero. The currentidx

Figure 3.8: Extracting elements from the linked listLa[idx]

is 3. We have to look for anη4j inLη[4], where j<idx. The algorithm finds theη41 =2 element, so the algorithm inserts the pointer of theη41toLa[1].

• The result of a dot product can be zero. In this case the algorithm removes that pointer from La, which refers an element of Lη that belongs to the linked list pivotIndex. This pointer can be obtained by a search algorithm, which complex-ity isO(m). However, this problem can be solved using redundancy: The arrayLd

contains the corresponding pointer fromLato each nonzero element ofa. This array ensures that finding above pointer hasO(1) complexity.

After each multiplication the elements of La[idx] will be removed or moved into an other linked list, as Figure (3.8) shows. If a pointer refers to anηij inLηwhich has a next element, then the algorithm adds the pointer of this next element to the correspondingLa

list. If the pointer was the last one in theLηlist, it will be erased.

Aspects of implementation considerations

In this section we introduce a few implementation techniques that improve the perfor-mance of the row-wise BTRAN.

The lists of the array Lηare implemented as arrays. Each array has a variable named size that is equal to the number of stored elements, and an other variable named capacity shows the capacity of the array. The size should never exceed the capacity. If the capacity is greater than the size, it means that there is place for further elements in the array. When these variables are equal, then we allocate a greater array. In certain iterations the simplex

Figure 3.9: A new element was added to vector aso La also gets a new element

Figure 3.10: The second element of a changes, but La remains the same

Algorithm 3.3Pseudo code of the row-wise BTRAN algorithm