1
0
mirror of https://gitlab.com/klmp200/LO27.git synced 2024-11-22 17:03:19 +00:00

Merge branch 'NaejBranch' into 'master'

Naej branch

See merge request !25
This commit is contained in:
Antoine Bartuccio 2017-01-01 23:30:39 +00:00
commit 4648c34686

View File

@ -32,7 +32,7 @@ BEGIN
getCellValue <- ERROR getCellValue <- ERROR
endif endif
if (findMatrixElem( matrix , ColPos , RowPos ) == NULL) if (findMatrixElem( matrix , ColPos , RowPos ) = NULL)
getCellValue <- false getCellValue <- false
endif endif
@ -45,7 +45,7 @@ BEGIN
elem:*cellElement <- NULL elem:*cellElement <- NULL
Row <- getElementPos(rows(matrix),RowPos) Row <- getElementPos(rows(matrix),RowPos)
if (Row == NULL) if (Row = NULL)
findMatrixElem <- NULL findMatrixElem <- NULL
endif endif
@ -60,10 +60,11 @@ END
``` ```
*setCellValue* is a simple function based on *createMatrixElem* and *deleteMatrixElement* : *setCellValue* is a simple function based on *createMatrixElem* and *deleteMatrixElement* :
```C ```C
setCellValue(matrix:Matrix, ColPos:integer, RowPos:integer,value:bool):bool setCellValue(matrix:Matrix, ColPos:integer, RowPos:integer,value:bool):bool
BEGIN BEGIN
if (value == true) if (value = true)
setCellValue <- createMatrixElem(matrix,ColPos,RowPos) setCellValue <- createMatrixElem(matrix,ColPos,RowPos)
else else
if ( deleteMatrixElem(matrix,ColPos,RowPos) >= 0 ) if ( deleteMatrixElem(matrix,ColPos,RowPos) >= 0 )
@ -84,7 +85,7 @@ createMatrixElem( matrix:Matrix, ColPos:integer, RowPos:integer):bool
tmp: *cellElement<- NULL tmp: *cellElement<- NULL
if (colCount(matrix) <= ColPos OR rowCount(matrix) <= RowPos ) if (colCount(matrix) <= ColPos OR rowCount(matrix) <= RowPos )
createMatrixElem <- ERROR createMatrixElem <- ERROR /* out of bounds */
endif endif
elem <- CreateCellElem() elem <- CreateCellElem()
@ -93,8 +94,8 @@ createMatrixElem( matrix:Matrix, ColPos:integer, RowPos:integer):bool
Row <- getElementPos(rows(matrix),RowPos) Row <- getElementPos(rows(matrix),RowPos)
if (Row != NULL AND data(Row) != NULL) if (Row != NULL AND data(Row) != NULL)
if (colIndex(data(Row)) == ColPos) if (colIndex(data(Row)) = ColPos)
error ++ error ++ /* the element already exists */
else else
if (colIndex(data(Row)) > ColPos) if (colIndex(data(Row)) > ColPos)
nextCol(elem) <- data(Row) nextCol(elem) <- data(Row)
@ -102,20 +103,21 @@ createMatrixElem( matrix:Matrix, ColPos:integer, RowPos:integer):bool
endif endif
else else
tmp <- data(Row) tmp <- data(Row)
/* searching the previous element */
while ( nextCol(tmp) != NULL AND nextCol(colIndex(tmp)) < ColPos) do while ( nextCol(tmp) != NULL AND nextCol(colIndex(tmp)) < ColPos) do
tmp <- nextCol(tmp) tmp <- nextCol(tmp)
endwhile endwhile
if ( nextCol(tmp) == NULL OR colIndex(nextCol(tmp)) > ColPos) if ( nextCol(tmp) = NULL OR colIndex(nextCol(tmp)) > ColPos)
nextCol(elem) <- nextCol(tmp) nextCol(elem) <- nextCol(tmp)
nextCol(tmp) <- elem nextCol(tmp) <- elem
else else
error ++ error ++ /* the element already exists */
endif endif
endif endif
else else
/* if the list is empty */
push(rows(matrix),elem) push(rows(matrix),elem)
pos(tail(rows(matrix))) <- RowPos pos(tail(rows(matrix))) <- RowPos
endif endif
@ -123,8 +125,8 @@ createMatrixElem( matrix:Matrix, ColPos:integer, RowPos:integer):bool
Col <- getElementPos(cols(matrix),ColPos) Col <- getElementPos(cols(matrix),ColPos)
if (Col != NULL AND data(Col) != NULL) if (Col != NULL AND data(Col) != NULL)
if (rowIndex(data(Col)) == RowPos) if (rowIndex(data(Col)) = RowPos)
error ++ error ++ /* the element already exists */
else else
if (rowIndex(data(Col)) > RowPos) if (rowIndex(data(Col)) > RowPos)
nextRow(elem) <- data(Col) nextRow(elem) <- data(Col)
@ -132,25 +134,28 @@ createMatrixElem( matrix:Matrix, ColPos:integer, RowPos:integer):bool
endif endif
else else
tmp <- data(Col) tmp <- data(Col)
/* searching the previous element */
while (nextRow(tmp) != NULL AND rowIndex(nextRow(tmp)) < RowPos) do while (nextRow(tmp) != NULL AND rowIndex(nextRow(tmp)) < RowPos) do
tmp <- nextRow(tmp) tmp <- nextRow(tmp)
endwhile endwhile
if (nextRow(tmp) == NULL OR rowIndex(nextRow(tmp)) > RowPos) if (nextRow(tmp) = NULL OR rowIndex(nextRow(tmp)) > RowPos)
nexRow(elem) <- nextRow(tmp) nexRow(elem) <- nextRow(tmp)
newRow(tmp) <- elem newRow(tmp) <- elem
else else
error ++ error ++ /* the element already exists */
endif endif
endif endif
else else
/* if the list is empty */
push(cols(matrix),elem) push(cols(matrix),elem)
pos(tail(cols(matrix))) <- ColPos pos(tail(cols(matrix))) <- ColPos
endif endif
if (error != 0) if (error != 0)
/* if the element already exists, free it */
FreeCellElement(elem) FreeCellElement(elem)
createMatrixElem <- true createMatrixElem <- true
else else
@ -168,64 +173,77 @@ BEGIN
Col : *ListElement <- NULL Col : *ListElement <- NULL
elem <- findMatrixElem(matrix,ColPos,RowPos) elem <- findMatrixElem(matrix,ColPos,RowPos)
if (elem == NULL) if (elem = NULL)
/* if the element does not exists */
deleteMatrixElem <- 0 deleteMatrixElem <- 0
endif endif
Row <- getElementPos(rows(matrix),RowPos) Row <- getElementPos(rows(matrix),RowPos)
if (Row == NULL) if (Row = NULL)
/* this shouldn't happend */
deleteMatrixElem <- -1 deleteMatrixElem <- -1
endif endif
if (data(Row) == NULL) if (data(Row) = NULL)
/* this shouldn't happend too */
removeElementPos(rows(matrix),RowPos) removeElementPos(rows(matrix),RowPos)
deleteMatrixElem <- -1 deleteMatrixElem <- -1
endif endif
if (colIndex(data(Row)) == ColPos) if (colIndex(data(Row)) = ColPos)
/* the element is the first element */
data(Row) <- nextCol(elem) data(Row) <- nextCol(elem)
else else
tmp <- data(Row) tmp <- data(Row)
/* finding prefious element */
while (nextCol(tmp) != NULL AND nextCol(tmp) != elem) do while (nextCol(tmp) != NULL AND nextCol(tmp) != elem) do
tmp <- nextCol(tmp) tmp <- nextCol(tmp)
endwhile endwhile
if (nextCol(tmp) != NULL) if (nextCol(tmp) != NULL)
/* linking correctly the previous element */
nextCol(tmp) <- nextCol(elem) nextCol(tmp) <- nextCol(elem)
endif endif
endif endif
if (data(Row) == NULL) if (data(Row) = NULL)
/* if the row is empty now we delete it to save memory */
removeElementPos(rows(matrix),RowPos) removeElementPos(rows(matrix),RowPos)
endif endif
Col <- getElementPos(cols(matrix),ColPos) Col <- getElementPos(cols(matrix),ColPos)
if (Col == NULL) if (Col = NULL)
/* this shouldn't happend */
deleteMatrixElem <- -2 deleteMatrixElem <- -2
endif endif
if (data(Col) == NULL) if (data(Col) = NULL)
/* this shouldn't happend too */
removeElementPos(cols(matrix),ColPos) removeElementPos(cols(matrix),ColPos)
deleteMatrixElem <- -1 deleteMatrixElem <- -1
endif endif
if (rowIndex(data(Col)) == RowPos)
if (rowIndex(data(Col)) = RowPos)
/* the element is the first element */
data(Col) <- nextRow(elem) data(Col) <- nextRow(elem)
else else
tmp <- data(Col) tmp <- data(Col)
/* finding prefious element */
while (nextRow(tmp) != NULL AND nextRow(tmp) != elem) do while (nextRow(tmp) != NULL AND nextRow(tmp) != elem) do
tmp <- nextRow(tmp) tmp <- nextRow(tmp)
endwhile endwhile
if (nextRow(tmp) != NULL) if (nextRow(tmp) != NULL)
/* linking correctly the previous element */
nextRow(tmp) <- nextRow(elem) nextRow(tmp) <- nextRow(elem)
endif endif
endif endif
if (data(Col) == NULL) if (data(Col) = NULL)
/* if the col is empty now we delete it to save memory */
removeElementPos(cols(matrix),ColPos) removeElementPos(cols(matrix),ColPos)
endif endif
@ -277,7 +295,7 @@ Here are the algorithm of the function *applyRules* and all the one related to i
```C ```C
applyRules ( matrix:Matrix, Rules:integer, N:integer):Matrix applyRules ( matrix:Matrix, Rules:integer, N:integer):Matrix
BEGIN BEGIN
RulesMatrix :integer[9] RulesMatrix :integer[9] /* the size is the number of fundamental rules */
i:integer <- 0 i:integer <- 0
power:integer <- 2 power:integer <- 2
sum:integer <- 0 sum:integer <- 0
@ -290,6 +308,7 @@ BEGIN
applyRules <- matrix applyRules <- matrix
endif endif
/* decompotition of the rule in basic rules */
while(power <= 512) do while(power <= 512) do
RulesMatrix[i] <- Rules%power - sum RulesMatrix[i] <- Rules%power - sum
@ -303,6 +322,8 @@ BEGIN
endwhile endwhile
/* application of the rule */
tempMatrix1 <- matrixFromRules(matrix, i, RulesMatrix) tempMatrix1 <- matrixFromRules(matrix, i, RulesMatrix)
for j from 0 to N do for j from 0 to N do
@ -315,8 +336,6 @@ BEGIN
applyRules <- tempMatrix1 applyRules <- tempMatrix1
END END
``` ```
# Conclusion # Conclusion