mirror of
https://gitlab.com/klmp200/LO27.git
synced 2024-12-23 03:31:07 +00:00
added algos
This commit is contained in:
parent
7761f897c5
commit
4c60e18161
@ -188,11 +188,6 @@ int deleteListContent(List *list){
|
|||||||
while (current != NULL){
|
while (current != NULL){
|
||||||
toDelete = current;
|
toDelete = current;
|
||||||
current = current->next;
|
current = current->next;
|
||||||
/*
|
|
||||||
if (toDelete->data != NULL){
|
|
||||||
FreeCellElement(toDelete->data);
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
free(toDelete);
|
free(toDelete);
|
||||||
}
|
}
|
||||||
list->head = NULL;
|
list->head = NULL;
|
||||||
|
@ -263,7 +263,6 @@ bool setCellValue(Matrix matrix, int ColPos, int RowPos,bool value){
|
|||||||
}
|
}
|
||||||
|
|
||||||
void printMatrix(Matrix matrix){
|
void printMatrix(Matrix matrix){
|
||||||
/* Non optimisé : debug fx */
|
|
||||||
int i = 0;
|
int i = 0;
|
||||||
int j = 0;
|
int j = 0;
|
||||||
bool b;
|
bool b;
|
||||||
@ -666,8 +665,3 @@ bool equalsMatrix(Matrix m1, Matrix m2){
|
|||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* todos :
|
|
||||||
*faire les fontions débiles qui restent
|
|
||||||
*ecrire doc
|
|
||||||
*/
|
|
||||||
|
257
report.md
257
report.md
@ -8,7 +8,7 @@
|
|||||||
|
|
||||||
The goal of this project is to provide a library containing a new abstract data type called **Matrix** with associated function to manipulate them. The final program have to enable a user to test the library in an interactive and practical way.
|
The goal of this project is to provide a library containing a new abstract data type called **Matrix** with associated function to manipulate them. The final program have to enable a user to test the library in an interactive and practical way.
|
||||||
|
|
||||||
Since we decided to not store false value in our matrix, we decided not to worry too much about performances and we encapsulated all access to stored data in the Matrix structure to avoid too much complexity and allow more modularity, readability and re-usability. We created high level tools to manipulate our matrix and used it all along the project.
|
Since we decided to not store false value \footnote{cellElement does not contains values anymore, their existence is their value}in our matrix and to not store the colElement and rowElement \footnote{they are unified and renamed as listElement}that are empty, we decided not to worry too much about performances and we encapsulated all access to stored data in the Matrix structure to avoid too much complexity and allow more modularity, readability and re-usability. We created high level tools to manipulate our matrix and used it all along the project.
|
||||||
|
|
||||||
For compilation we didn't used the **-ansi** flag since we had to deal with both clang and gcc for compilation and clang didn't accept this flag. Instead, we used the **-std=c89** flag witch contains the same rules but is accepted on both softwares. Compiling with **-ansi** still works.
|
For compilation we didn't used the **-ansi** flag since we had to deal with both clang and gcc for compilation and clang didn't accept this flag. Instead, we used the **-std=c89** flag witch contains the same rules but is accepted on both softwares. Compiling with **-ansi** still works.
|
||||||
|
|
||||||
@ -23,8 +23,216 @@ Every function and data type are described in the documentation given with the p
|
|||||||
|
|
||||||
The most interesting function are *getCellValue* and *setCellValue*. Those are the one we rely on the most. They are our way of dealing with our complex data structure allowing us to avoid to store false values. They are the functions that need the more computational power on the long run but are really useful due to their level of abstraction and their high level.
|
The most interesting function are *getCellValue* and *setCellValue*. Those are the one we rely on the most. They are our way of dealing with our complex data structure allowing us to avoid to store false values. They are the functions that need the more computational power on the long run but are really useful due to their level of abstraction and their high level.
|
||||||
|
|
||||||
```C
|
*getCellValue* is a simple function based on *findMatrixElem* :
|
||||||
|
|
||||||
|
```C
|
||||||
|
getCellValue(matrix:Matrix, ColPos:integer , RowPos:integer ) : bool
|
||||||
|
BEGIN
|
||||||
|
if ( colCount(matrix) <= ColPos OR rowCount(matrix) <= RowPos)
|
||||||
|
getCellValue <- ERROR
|
||||||
|
endif
|
||||||
|
|
||||||
|
if (findMatrixElem( matrix , ColPos , RowPos ) == NULL)
|
||||||
|
getCellValue <- false
|
||||||
|
endif
|
||||||
|
|
||||||
|
getCellValue <- true
|
||||||
|
END
|
||||||
|
|
||||||
|
findMatrixElem( matrix:Matrix , ColPos:integer, RowPos:integer ) : *cellElement
|
||||||
|
BEGIN
|
||||||
|
Row:ListElement <- NULL
|
||||||
|
elem:*cellElement <- NULL
|
||||||
|
|
||||||
|
Row <- getElementPos(rows(matrix),RowPos)
|
||||||
|
if (Row == NULL)
|
||||||
|
findMatrixElem <- NULL
|
||||||
|
endif
|
||||||
|
|
||||||
|
elem <- data(Row)
|
||||||
|
|
||||||
|
while (elem != NULL AND colIndex(elem) != ColPos)
|
||||||
|
elem <- nextCol(elem)
|
||||||
|
endwhile
|
||||||
|
|
||||||
|
findMatrixElem <- elem;
|
||||||
|
END
|
||||||
|
```
|
||||||
|
|
||||||
|
*setCellValue* is a simple function based on *createMatrixElem* and *deleteMatrixElement* :
|
||||||
|
```C
|
||||||
|
setCellValue(matrix:Matrix, ColPos:integer, RowPos:integer,value:bool):bool
|
||||||
|
BEGIN
|
||||||
|
if (value == true)
|
||||||
|
setCellValue <- createMatrixElem(matrix,ColPos,RowPos)
|
||||||
|
else
|
||||||
|
if ( deleteMatrixElem(matrix,ColPos,RowPos) >= 0 )
|
||||||
|
setCellValue <- true
|
||||||
|
else
|
||||||
|
setCellValue <- false
|
||||||
|
endif
|
||||||
|
endif
|
||||||
|
END
|
||||||
|
|
||||||
|
createMatrixElem( matrix:Matrix, ColPos:integer, RowPos:integer):bool
|
||||||
|
Row:*ListElement <-NULL
|
||||||
|
Col:*Listelemnt <- NULL
|
||||||
|
|
||||||
|
error:integer = 0
|
||||||
|
|
||||||
|
elem: *cellElement <- NULL
|
||||||
|
tmp: *cellElement<- NULL
|
||||||
|
|
||||||
|
if (colCount(matrix) <= ColPos OR rowCount(matrix) <= RowPos )
|
||||||
|
createMatrixElem <- ERROR
|
||||||
|
endif
|
||||||
|
|
||||||
|
elem <- CreateCellElem()
|
||||||
|
SetPositionIndex(elem,ColPos,RowPos)
|
||||||
|
|
||||||
|
Row <- getElementPos(rows(matrix),RowPos)
|
||||||
|
if (Row != NULL AND Row->data != NULL)
|
||||||
|
|
||||||
|
if (colIndex(data(Row)) == ColPos)
|
||||||
|
error ++
|
||||||
|
else
|
||||||
|
if (colIndex(data(Row)) > ColPos)
|
||||||
|
nextCol(elem) <- data(Row)
|
||||||
|
data(Row) <- elem
|
||||||
|
endif
|
||||||
|
else
|
||||||
|
tmp <- data(Row)
|
||||||
|
|
||||||
|
while ( nextCol(tmp) != NULL AND nextCol(colIndex(tmp)) < ColPos) do
|
||||||
|
tmp <- nextCol(tmp)
|
||||||
|
endwhile
|
||||||
|
|
||||||
|
if ( nextCol(tmp) == NULL OR colIndex(nextCol(tmp)) > ColPos)
|
||||||
|
nextCol(elem) <- nextCol(tmp)
|
||||||
|
nextCol(tmp) <- elem
|
||||||
|
else
|
||||||
|
error ++
|
||||||
|
endif
|
||||||
|
endif
|
||||||
|
|
||||||
|
else
|
||||||
|
push(rows(matrix),elem)
|
||||||
|
pos(tail(rows(matrix))) <- RowPos
|
||||||
|
endif
|
||||||
|
|
||||||
|
Col <- getElementPos(cols(matrix),ColPos)
|
||||||
|
if (Col != NULL AND data(Col) != NULL)
|
||||||
|
|
||||||
|
if (rowIndex(data(Col)) == RowPos)
|
||||||
|
error ++
|
||||||
|
else
|
||||||
|
if (rowIndex(data(Col)) > RowPos)
|
||||||
|
nextRow(elem) <- data(Col)
|
||||||
|
data(Col) <- elem
|
||||||
|
endif
|
||||||
|
else
|
||||||
|
tmp <- data(Col)
|
||||||
|
while (nextRow(tmp) != NULL AND rowIndex(nextRow(tmp)) < RowPos) do
|
||||||
|
tmp = nextRow(tmp)
|
||||||
|
endwhile
|
||||||
|
|
||||||
|
if (nextRow(tmp) == NULL OR rowIndex(nextRow(tmp)) > RowPos)
|
||||||
|
nexRow(elem) <- nextRow(tmp)
|
||||||
|
newRow(tmp) <- elem
|
||||||
|
else
|
||||||
|
error ++
|
||||||
|
endif
|
||||||
|
endif
|
||||||
|
|
||||||
|
else
|
||||||
|
push(cols(matrix),elem)
|
||||||
|
pos(tail(cols(matrix))) = ColPos;
|
||||||
|
endif
|
||||||
|
|
||||||
|
|
||||||
|
if (error != 0)
|
||||||
|
FreeCellElement(elem)
|
||||||
|
createMatrixElem <- true
|
||||||
|
else
|
||||||
|
createMatrixElem <- false
|
||||||
|
endif
|
||||||
|
|
||||||
|
END
|
||||||
|
|
||||||
|
deleteMatrixElem(matrix:Matrix,ColPos:integer, RowPos:integer ):integer
|
||||||
|
BEGIN
|
||||||
|
elem : *cellElement <- NULL
|
||||||
|
tmp : *cellElement <- NULL
|
||||||
|
|
||||||
|
Row : *ListElement <- NULL
|
||||||
|
Col : *ListElement <- NULL
|
||||||
|
|
||||||
|
elem <- findMatrixElem(matrix,ColPos,RowPos)
|
||||||
|
if (elem == NULL)
|
||||||
|
deleteMatrixElem <- 0
|
||||||
|
endif
|
||||||
|
|
||||||
|
Row <- getElementPos(rows(matrix),RowPos)
|
||||||
|
if (Row == NULL)
|
||||||
|
deleteMatrixElem <- -1
|
||||||
|
endif
|
||||||
|
|
||||||
|
if (Row->data == NULL)
|
||||||
|
removeElementPos(rows(matrix),RowPos)
|
||||||
|
deleteMatrixElem <- -1
|
||||||
|
endif
|
||||||
|
|
||||||
|
if (colIndex(data(Row)) == ColPos)
|
||||||
|
data(Row) <- nextCol(elem)
|
||||||
|
else
|
||||||
|
tmp <- data(Row)
|
||||||
|
|
||||||
|
while (nextCol(tmp) != NULL AND nextCol(tmp) != elem) do
|
||||||
|
tmp <- nextCol(tmp)
|
||||||
|
endwhile
|
||||||
|
|
||||||
|
if (tmp->nextCol != NULL)
|
||||||
|
nextCol(tmp) <- nextCol(elem)
|
||||||
|
endif
|
||||||
|
|
||||||
|
endif
|
||||||
|
|
||||||
|
if (data(Row) == NULL){
|
||||||
|
removeElementPos(rows(matrix),RowPos)
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Col = getElementPos(cols(matrix),ColPos)
|
||||||
|
if (Col == NULL)
|
||||||
|
deleteMatrixElem <- -2
|
||||||
|
endif
|
||||||
|
|
||||||
|
if (Col->data == NULL){
|
||||||
|
removeElementPos(cols(matrix),ColPos)
|
||||||
|
deleteMatrixElem <- -1;
|
||||||
|
endif
|
||||||
|
if (rowIndex(data(Col)) == RowPos)
|
||||||
|
data(Col) <- nextRow(elem)
|
||||||
|
else
|
||||||
|
tmp <- data(Col)
|
||||||
|
while (nextRow(tmp) != NULL AND nextRow(tmp) != elem) do
|
||||||
|
tmp <- nextRow(tmp)
|
||||||
|
endwhile
|
||||||
|
|
||||||
|
if (nextRow(tmp) != NULL)
|
||||||
|
nextRow(tmp) <- nextRow(elem)
|
||||||
|
endif
|
||||||
|
|
||||||
|
endif
|
||||||
|
|
||||||
|
if (data(Col) == NULL)
|
||||||
|
removeElementPos(cols(matrix),ColPos)
|
||||||
|
endif
|
||||||
|
|
||||||
|
FreeCellElement(elem)
|
||||||
|
deleteMatrixElem <- 1
|
||||||
|
|
||||||
|
END
|
||||||
```
|
```
|
||||||
|
|
||||||
Functions *andColSequenceOnMatrix* and *orColSequenceOnMatrix* are implemented with *colSequenceOnMatrix* and are really not interesting so we're gonna provide the algorithm of the last one :
|
Functions *andColSequenceOnMatrix* and *orColSequenceOnMatrix* are implemented with *colSequenceOnMatrix* and are really not interesting so we're gonna provide the algorithm of the last one :
|
||||||
@ -51,8 +259,8 @@ BEGIN
|
|||||||
endif
|
endif
|
||||||
colCount(newM) <- colCount(m) - 1
|
colCount(newM) <- colCount(m) - 1
|
||||||
|
|
||||||
for i from 0 to colCount(m) - 2, step 1
|
for i from 0 to colCount(m) - 2 do
|
||||||
for j from 0 to rowCount(m) - 2, step 1
|
for j from 0 to rowCount(m) - 2 do
|
||||||
a <- getCellValue(m, i, j)
|
a <- getCellValue(m, i, j)
|
||||||
b <- getCellValue(m, i + 1, j)
|
b <- getCellValue(m, i + 1, j)
|
||||||
if operator(a, b) then
|
if operator(a, b) then
|
||||||
@ -67,6 +275,47 @@ END
|
|||||||
Here are the algorithm of the function *applyRules* and all the one related to it :
|
Here are the algorithm of the function *applyRules* and all the one related to it :
|
||||||
|
|
||||||
```C
|
```C
|
||||||
|
applyRules ( matrix:Matrix, Rules:integer, N:integer):Matrix
|
||||||
|
BEGIN
|
||||||
|
RulesMatrix :integer[9]
|
||||||
|
i:integer <- 0
|
||||||
|
power:integer <- 2
|
||||||
|
sum:integer <- 0
|
||||||
|
j:integer <- 0
|
||||||
|
|
||||||
|
tempMatrix1:Matrix
|
||||||
|
tempMatrix2:Matrix
|
||||||
|
|
||||||
|
if (Rules <= 0 OR N < 1)
|
||||||
|
applyRules <- matrix;
|
||||||
|
endif
|
||||||
|
|
||||||
|
while(power <= 512) do
|
||||||
|
|
||||||
|
RulesMatrix[i] <- Rules%power - sum
|
||||||
|
sum <- Rules%power
|
||||||
|
|
||||||
|
if (RulesMatrix[i]!=0)
|
||||||
|
i++
|
||||||
|
endif
|
||||||
|
|
||||||
|
power <- power*2
|
||||||
|
|
||||||
|
endwhile
|
||||||
|
|
||||||
|
tempMatrix1 <- matrixFromRules(matrix, i, RulesMatrix)
|
||||||
|
|
||||||
|
for j from 0 to N do
|
||||||
|
tempMatrix2 <- matrixFromRules(tempMatrix1 ,i, RulesMatrix)
|
||||||
|
freeMatrix(tempMatrix1)
|
||||||
|
|
||||||
|
tempMatrix1 <- tempMatrix2
|
||||||
|
endfor
|
||||||
|
|
||||||
|
applyRules <- tempMatrix1
|
||||||
|
|
||||||
|
END
|
||||||
|
|
||||||
|
|
||||||
```
|
```
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user