Compare commits

..

No commits in common. "60a7af738ce4bb32d1c7dbd47d404007e4df651a" and "461bb1d420239fa1e556719a3eb79555a69d8d7e" have entirely different histories.

28 changed files with 262 additions and 1612 deletions

0
.gitignore vendored Normal file → Executable file
View File

8
.idea/.gitignore vendored Normal file
View File

@ -0,0 +1,8 @@
# Default ignored files
/shelf/
/workspace.xml
# Editor-based HTTP Client requests
/httpRequests/
# Datasource local storage ignored files
/dataSources/
/dataSources.local.xml

103
.idea/editor.xml Normal file
View File

@ -0,0 +1,103 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="BackendCodeEditorSettings">
<option name="/Default/Housekeeping/GlobalSettingsUpgraded/IsUpgraded/@EntryValue" value="true" type="bool" />
<option name="/Default/CodeStyle/CodeFormatting/CppClangFormat/EnableClangFormatSupport/@EntryValue" value="false" type="bool" />
<option name="/Default/CodeStyle/EditorConfig/EnableClangFormatSupport/@EntryValue" value="false" type="bool" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/ALIGN_MULTILINE_BINARY_EXPRESSIONS_CHAIN/@EntryValue" value="true" type="bool" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/ALIGN_MULTILINE_CALLS_CHAIN/@EntryValue" value="false" type="bool" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/ALIGN_MULTILINE_EXPRESSION/@EntryValue" value="false" type="bool" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/ALIGN_MULTILINE_FOR_STMT/@EntryValue" value="true" type="bool" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/ALIGN_MULTIPLE_DECLARATION/@EntryValue" value="false" type="bool" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/ALIGN_TERNARY/@EntryValue" value="ALIGN_ALL" type="string" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/BLANK_LINES_AROUND_CLASS_DEFINITION/@EntryValue" value="1" type="int" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/KEEP_BLANK_LINES_IN_DECLARATIONS/@EntryValue" value="2" type="int" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/KEEP_BLANK_LINES_IN_CODE/@EntryValue" value="2" type="int" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/KEEP_USER_LINEBREAKS/@EntryValue" value="true" type="bool" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/INDENT_CASE_FROM_SWITCH/@EntryValue" value="true" type="bool" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/INDENT_COMMENT/@EntryValue" value="true" type="bool" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/INT_ALIGN_EQ/@EntryValue" value="false" type="bool" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/SIMPLE_BLOCK_STYLE/@EntryValue" value="DO_NOT_CHANGE" type="string" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/SPACE_AFTER_COMMA_IN_TEMPLATE_ARGS/@EntryValue" value="true" type="bool" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/SPACE_AFTER_COMMA_IN_TEMPLATE_PARAMS/@EntryValue" value="true" type="bool" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/SPACE_AFTER_FOR_SEMICOLON/@EntryValue" value="true" type="bool" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/SPACE_BEFORE_FOR_SEMICOLON/@EntryValue" value="false" type="bool" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/SPACE_AFTER_UNARY_OPERATOR/@EntryValue" value="false" type="bool" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/SPACE_WITHIN_ARRAY_ACCESS_BRACKETS/@EntryValue" value="false" type="bool" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/SPACE_WITHIN_CAST_EXPRESSION_PARENTHESES/@EntryValue" value="false" type="bool" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/SPACE_WITHIN_EMPTY_INITIALIZER_BRACES/@EntryValue" value="false" type="bool" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/SPACE_WITHIN_EMPTY_METHOD_PARENTHESES/@EntryValue" value="false" type="bool" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/SPACE_WITHIN_INITIALIZER_BRACES/@EntryValue" value="false" type="bool" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/SPECIAL_ELSE_IF_TREATMENT/@EntryValue" value="true" type="bool" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/SPACE_AFTER_CAST_EXPRESSION_PARENTHESES/@EntryValue" value="true" type="bool" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/WRAP_AFTER_BINARY_OPSIGN/@EntryValue" value="true" type="bool" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/WRAP_BEFORE_TERNARY_OPSIGNS/@EntryValue" value="true" type="bool" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/TYPE_DECLARATION_BRACES/@EntryValue" value="END_OF_LINE" type="string" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/OTHER_BRACES/@EntryValue" value="END_OF_LINE" type="string" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/CASE_BLOCK_BRACES/@EntryValue" value="END_OF_LINE" type="string" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/BLANK_LINES_AROUND_FUNCTION_DECLARATION/@EntryValue" value="1" type="int" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/BLANK_LINES_AROUND_FUNCTION_DEFINITION/@EntryValue" value="1" type="int" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/PLACE_WHILE_ON_NEW_LINE/@EntryValue" value="false" type="bool" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/PLACE_ELSE_ON_NEW_LINE/@EntryValue" value="false" type="bool" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/PLACE_CATCH_ON_NEW_LINE/@EntryValue" value="false" type="bool" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/NAMESPACE_INDENTATION/@EntryValue" value="All" type="string" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/ALIGN_MULTILINE_ARGUMENT/@EntryValue" value="true" type="bool" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/ALIGN_MULTILINE_EXTENDS_LIST/@EntryValue" value="true" type="bool" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/ALIGN_MULTILINE_PARAMETER/@EntryValue" value="true" type="bool" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/ALIGN_MULTILINE_TYPE_ARGUMENT/@EntryValue" value="false" type="bool" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/ALIGN_MULTILINE_TYPE_PARAMETER/@EntryValue" value="false" type="bool" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/BLANK_LINES_AROUND_DECLARATIONS/@EntryValue" value="0" type="int" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/INDENT_ACCESS_SPECIFIERS_FROM_CLASS/@EntryValue" value="false" type="bool" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/INDENT_CLASS_MEMBERS_FROM_ACCESS_SPECIFIERS/@EntryValue" value="true" type="bool" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/LINE_BREAK_AFTER_COLON_IN_MEMBER_INITIALIZER_LISTS/@EntryValue" value="ON_SINGLE_LINE" type="string" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/MEMBER_INITIALIZER_LIST_STYLE/@EntryValue" value="DO_NOT_CHANGE" type="string" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/PLACE_NAMESPACE_DEFINITIONS_ON_SAME_LINE/@EntryValue" value="false" type="bool" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/SPACE_AFTER_COLON_IN_BITFIELD_DECLARATOR/@EntryValue" value="true" type="bool" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/SPACE_BEFORE_COLON_IN_BITFIELD_DECLARATOR/@EntryValue" value="false" type="bool" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/SPACE_AFTER_EXTENDS_COLON/@EntryValue" value="true" type="bool" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/SPACE_BEFORE_EXTENDS_COLON/@EntryValue" value="true" type="bool" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/SPACE_AFTER_FOR_COLON/@EntryValue" value="true" type="bool" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/SPACE_BEFORE_FOR_COLON/@EntryValue" value="false" type="bool" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/SPACE_AFTER_PTR_IN_DATA_MEMBER/@EntryValue" value="false" type="bool" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/SPACE_AFTER_PTR_IN_DATA_MEMBERS/@EntryValue" value="false" type="bool" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/SPACE_AFTER_PTR_IN_METHOD/@EntryValue" value="false" type="bool" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/SPACE_AFTER_PTR_IN_NESTED_DECLARATOR/@EntryValue" value="false" type="bool" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/SPACE_AFTER_REF_IN_DATA_MEMBER/@EntryValue" value="false" type="bool" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/SPACE_AFTER_REF_IN_DATA_MEMBERS/@EntryValue" value="false" type="bool" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/SPACE_AFTER_REF_IN_METHOD/@EntryValue" value="false" type="bool" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/SPACE_BEFORE_PTR_IN_ABSTRACT_DECL/@EntryValue" value="true" type="bool" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/SPACE_BEFORE_PTR_IN_DATA_MEMBER/@EntryValue" value="true" type="bool" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/SPACE_BEFORE_PTR_IN_DATA_MEMBERS/@EntryValue" value="true" type="bool" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/SPACE_BEFORE_PTR_IN_METHOD/@EntryValue" value="true" type="bool" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/SPACE_BEFORE_REF_IN_ABSTRACT_DECL/@EntryValue" value="true" type="bool" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/SPACE_BEFORE_REF_IN_DATA_MEMBER/@EntryValue" value="true" type="bool" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/SPACE_BEFORE_REF_IN_DATA_MEMBERS/@EntryValue" value="true" type="bool" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/SPACE_BEFORE_REF_IN_METHOD/@EntryValue" value="true" type="bool" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/SPACE_BEFORE_TEMPLATE_ARGS/@EntryValue" value="false" type="bool" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/SPACE_BEFORE_TEMPLATE_PARAMS/@EntryValue" value="false" type="bool" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/SPACE_BETWEEN_CLOSING_ANGLE_BRACKETS_IN_TEMPLATE_ARGS/@EntryValue" value="true" type="bool" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/SPACE_WITHIN_EMPTY_TEMPLATE_PARAMS/@EntryValue" value="false" type="bool" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/SPACE_WITHIN_TEMPLATE_ARGS/@EntryValue" value="false" type="bool" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/SPACE_WITHIN_TEMPLATE_PARAMS/@EntryValue" value="false" type="bool" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/SPACE_WITHIN_DECLARATION_PARENTHESES/@EntryValue" value="false" type="bool" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/SPACE_WITHIN_EMPTY_BLOCKS/@EntryValue" value="false" type="bool" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/WRAP_BEFORE_INVOCATION_LPAR/@EntryValue" value="false" type="bool" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/WRAP_AFTER_INVOCATION_LPAR/@EntryValue" value="false" type="bool" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/WRAP_BEFORE_INVOCATION_RPAR/@EntryValue" value="false" type="bool" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/WRAP_BEFORE_DECLARATION_LPAR/@EntryValue" value="false" type="bool" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/WRAP_AFTER_DECLARATION_LPAR/@EntryValue" value="false" type="bool" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/WRAP_BEFORE_DECLARATION_RPAR/@EntryValue" value="false" type="bool" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/WRAP_ARGUMENTS_STYLE/@EntryValue" value="WRAP_IF_LONG" type="string" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/WRAP_PARAMETERS_STYLE/@EntryValue" value="WRAP_IF_LONG" type="string" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/BREAK_TEMPLATE_DECLARATION/@EntryValue" value="LINE_BREAK" type="string" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/NAMESPACE_DECLARATION_BRACES/@EntryValue" value="END_OF_LINE" type="string" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/FREE_BLOCK_BRACES/@EntryValue" value="END_OF_LINE" type="string" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/INVOCABLE_DECLARATION_BRACES/@EntryValue" value="END_OF_LINE" type="string" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/ANONYMOUS_METHOD_DECLARATION_BRACES/@EntryValue" value="END_OF_LINE" type="string" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/INITIALIZER_BRACES/@EntryValue" value="END_OF_LINE_NO_SPACE" type="string" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/INDENT_STYLE/@EntryValue" value="Space" type="string" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/INDENT_SIZE/@EntryValue" value="4" type="int" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/CONTINUOUS_LINE_INDENT/@EntryValue" value="Double" type="string" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/TAB_WIDTH/@EntryValue" value="4" type="int" />
</component>
</project>

18
.idea/misc.xml Normal file
View File

@ -0,0 +1,18 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ExternalStorageConfigurationManager" enabled="true" />
<component name="MakefileSettings">
<option name="linkedExternalProjectsSettings">
<MakefileProjectSettings>
<option name="externalProjectPath" value="$PROJECT_DIR$" />
<option name="modules">
<set>
<option value="$PROJECT_DIR$" />
</set>
</option>
<option name="version" value="2" />
</MakefileProjectSettings>
</option>
</component>
<component name="MakefileWorkspace" PROJECT_DIR="$PROJECT_DIR$" />
</project>

6
.idea/vcs.xml Normal file
View File

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="" vcs="Git" />
</component>
</project>

18
.vscode/c_cpp_properties.json vendored Executable file
View File

@ -0,0 +1,18 @@
{
"configurations": [
{
"name": "linux-gcc-x64",
"includePath": [
"${workspaceFolder}/**"
],
"compilerPath": "/usr/bin/gcc",
"cStandard": "${default}",
"cppStandard": "${default}",
"intelliSenseMode": "linux-gcc-x64",
"compilerArgs": [
""
]
}
],
"version": 4
}

24
.vscode/launch.json vendored Executable file
View File

@ -0,0 +1,24 @@
{
"version": "0.2.0",
"configurations": [
{
"name": "C/C++ Runner: Debug Session",
"type": "cppdbg",
"request": "launch",
"args": [],
"stopAtEntry": false,
"externalConsole": false,
"cwd": "/home/debian/Desktop/colloscope/src",
"program": "/home/debian/Desktop/colloscope/src/build/Debug/outDebug",
"MIMode": "gdb",
"miDebuggerPath": "gdb",
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
]
}
]
}

59
.vscode/settings.json vendored Executable file
View File

@ -0,0 +1,59 @@
{
"C_Cpp_Runner.cCompilerPath": "gcc",
"C_Cpp_Runner.cppCompilerPath": "g++",
"C_Cpp_Runner.debuggerPath": "gdb",
"C_Cpp_Runner.cStandard": "",
"C_Cpp_Runner.cppStandard": "",
"C_Cpp_Runner.msvcBatchPath": "",
"C_Cpp_Runner.useMsvc": false,
"C_Cpp_Runner.warnings": [
"-Wall",
"-Wextra",
"-Wpedantic",
"-Wshadow",
"-Wformat=2",
"-Wcast-align",
"-Wconversion",
"-Wsign-conversion",
"-Wnull-dereference"
],
"C_Cpp_Runner.msvcWarnings": [
"/W4",
"/permissive-",
"/w14242",
"/w14287",
"/w14296",
"/w14311",
"/w14826",
"/w44062",
"/w44242",
"/w14905",
"/w14906",
"/w14263",
"/w44265",
"/w14928"
],
"C_Cpp_Runner.enableWarnings": true,
"C_Cpp_Runner.warningsAsError": false,
"C_Cpp_Runner.compilerArgs": [],
"C_Cpp_Runner.linkerArgs": [],
"C_Cpp_Runner.includePaths": [],
"C_Cpp_Runner.includeSearch": [
"*",
"**/*"
],
"C_Cpp_Runner.excludeSearch": [
"**/build",
"**/build/**",
"**/.*",
"**/.*/**",
"**/.vscode",
"**/.vscode/**"
],
"C_Cpp_Runner.useAddressSanitizer": false,
"C_Cpp_Runner.useUndefinedSanitizer": false,
"C_Cpp_Runner.useLeakSanitizer": false,
"C_Cpp_Runner.showCompilationTime": false,
"C_Cpp_Runner.useLinkTimeOptimization": false,
"C_Cpp_Runner.msvcSecureNoWarnings": false
}

0
LICENSE Normal file → Executable file
View File

0
MP2I-colleurs.txt Normal file → Executable file
View File

0
MP2I-creneaux.txt Normal file → Executable file
View File

4
Makefile Normal file → Executable file
View File

@ -6,10 +6,10 @@ LFLAGS=
all: bin/colloscope
test: bin/colloscope
bin/colloscope -v S3-creneaux.txt 31 S3-colleurs.txt 16 7 15 2500 output-S3.csv 3 6 S3-tds.txt
bin/colloscope -v S3-creneaux.txt 31 S3-colleurs.txt 16 7 15 3000 output-S3.csv 3 6
mem: bin/
valgrind --leak-check=full ./bin/colloscope -v S3-creneaux.txt 31 S3-colleurs.txt 16 7 15 100 output-S3.csv 3 6 "S3-tds.txt"
valgrind --leak-check=full ./bin/colloscope -v S3-creneaux.txt 31 S3-colleurs.txt 16 7 15 100 output-S3.csv 3 6
OBJECTS = obj/structure.o obj/algorithm.o obj/display.o obj/logger.o obj/main.o
bin/colloscope: $(OBJECTS)

View File

@ -1,8 +0,0 @@
# Colloscope - un générateur de colloscope, par Alexandre Aboujaib
Detailled documentation about each feature coming soon !
Usage :
```bash
colloscope -v S3-creneaux.txt 31 S3-colleurs.txt 16 7 15 2500 output-S3.csv 3 6 S3-tds.txt
```

0
S3-colleurs.txt Normal file → Executable file
View File

0
S3-creneaux.txt Normal file → Executable file
View File

11
S3-tds.txt Normal file → Executable file
View File

@ -22,15 +22,4 @@ A
2
3
+
16 26 4 2024
T
1
3
5
7
9
11
13
15
+
$

View File

@ -1,745 +0,0 @@
/*
* Colloscope - A program that generates a colloscope for French 'classes prépas'
* Copyright (C) 2024 Alexandre Aboujaib
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include "logger.h"
#include "structure.h"
#include "algorithm.h"
bool is_equal_date(date d1, date d2) {
return (d1.hour == d2.hour && d1.day == d2.day && d2.month == d1.month && d2.year == d1.year);
}
int get_date_index(creneau* edt, int len_creneau, date d) {
// could be done in log(n), I know
// yields the 1st occurence of d in edt
int x = -1;
for(int i = 0; i < len_creneau; i++) {
x = date_dist(d, edt[i].date);
if(x >= 0) {
return i;
}
}
return -1;
}
int get_next_friday(creneau* edt, int len_creneau, date d) {
// could be done in log(n), I know again
int x = -1;
for(int i = 0; i < len_creneau; i++) {
x = date_dist(d, edt[i].date);
if(x >= 0 && (i == len_creneau-1 || date_dist(d, edt[i+1].date) - x > 1)) {
return i;
}
}
return -1;
}
// typedef struct colleur {char* name; int namelen; topic mat; date* disp; int n_disp;} colleur;
colleur* get_colleurs(colleur* cl, int len_cl, date d, int* how_many) {
colleur* res = malloc(sizeof(colleur)*30); // max. 3 colles per creneau
int ptr = 0;
for(int i = 0; i < len_cl; i++) {
for(int j = 0; j < cl[i].n_disp; j++) {
if(is_equal_date(cl[i].disp[j], d)) {
if(ptr >= 30) {
warn("Too many colleurs detected for a creneau\n");
}
res[ptr] = cl[i];
ptr++;
j = cl[i].n_disp;
}
}
}
*how_many = ptr;
return res;
}
void swap(int* arr, int i, int j) {
if(i != j) {
arr[i] += arr[j];
arr[j] = arr[i] - arr[j];
arr[i] -= arr[j];
}
}
void generate_random_perm(int* arr, int len) {
// generate a random perm of int between 0 and len-1
for(int i = 0; i < len; i++) {
arr[i] = i;
}
for(int i = 0; i < len; i++) {
swap(arr, i, rand()%len);
}
}
void print_arr(int* arr, int len) {
printf("[");
for(int i = 0; i < len; i++) {
printf("%d ", arr[i]);
}
printf("]\n");
}
void add_colle(creneau* edt, colleur* chads, int grp, int id_edt, int id_chad) {
edt[id_edt].group = grp;
edt[id_edt].namelen = chads[id_chad].namelen;
str_copy(chads[id_chad].name, chads[id_chad].namelen, edt[id_edt].name);
edt[id_edt].mat = chads[id_chad].mat;
}
void remove_colle(creneau* edt, int id_edt) {
edt[id_edt].group = 0;
edt[id_edt].namelen = 0;
str_copy("none", 4, edt[id_edt].name);
edt[id_edt].mat = NOTHING;
}
void move_colle(creneau* edt, int len_edt, int id_src, int id_dest) {
if((id_src < len_edt && id_src >= 0 && id_dest < len_edt && id_dest >= 0) == false) {
printf("Bad\n");
exit(1);
}
edt[id_dest].group = edt[id_src].group;
edt[id_dest].namelen = edt[id_src].namelen;
str_copy(edt[id_src].name, edt[id_src].namelen, edt[id_dest].name);
edt[id_dest].mat = edt[id_src].mat;
remove_colle(edt, id_src);
}
int mem_id(creneau* edt, int len_edt, int grp, char* colleur, int offset) {
for(int i = offset; i < len_edt; i++) {
if(edt[i].group == grp && str_equal(edt[i].name, colleur)) {
return i;
}
}
return -1;
}
bool is_overlap(creneau* edt, int len_edt, int id) { // detect if a colleur has 2 colles at the same time
int k = 1;
while(id+k < len_edt && is_equal_date(edt[id].date, edt[id+k].date)) {
if(str_equal(edt[id].name, edt[id+k].name)) {
return true;
}
k++;
}
k = 1;
while(id-k >= 0 && is_equal_date(edt[id].date, edt[id-k].date)) {
if(str_equal(edt[id].name, edt[id-k].name)) {
return true;
}
k++;
}
return false;
}
bool is_overlap_creneau(creneau* edt, int len_edt, int id, int grp) { // detect if a group has 2 overlapping colles
int k = 1;
while((id+k < len_edt && edt[id+k].date.hour - edt[id].date.hour < edt[id].length) && edt[id+k].date.day == edt[id].date.day) {
if(edt[id+k].group == grp) {
return true;
}
k++;
}
k = 1;
while(id-k >= 0 && is_equal_date(edt[id].date, edt[id-k].date)) {
if(edt[id+k].group == grp) {
return true;
}
k++;
}
return false;
}
int free_math_space(creneau* edt, int len_edt, int id) {
int k = 1;
int howmany = 0;
while(id+k < len_edt && is_equal_date(edt[id].date, edt[id+k].date)) {
if(edt[id+k].mat == NOTHING || edt[id+k].mat == MATH) {
howmany++;
}
k++;
}
k = 1;
while(id-k >= 0 && is_equal_date(edt[id].date, edt[id-k].date)) {
if(edt[id-k].mat == NOTHING || edt[id-k].mat == MATH) {
howmany++;
}
k++;
}
return howmany;
}
void add_colles_for_group_MP2I(int* weeks_len, creneau* edt, int len_edt, colleur* chads, int len_chads, int n_weeks, int grp, topic start_rotation, int mth, int inf, int* skip_count, int mat_halt, int info_app) {
topic rotation = start_rotation; // physics/english rotation
int math = mth; // math (3/4)
int info = inf; // info (1/6)
int r; // randomize the 1st date
int k = 0; // offset
int halt = 0; // timeout in case a colle cannot be placed
bool found; // interrupt in case a valid colle has been found
int remaining_to_add = 0; /* self-explainatory
please note that this also tells what colle to add :
1 = physics/english colle
2 = math
3 (not implemented) = info
*/
int len_dudes = 0; // length of colleur*
int len_perm = 0; // length of int*
int math_dude = 0; // length of colleur*
int weeklen;
bool normal_skip = true;
for(int week = 0; week < n_weeks; week++) {
weeklen = weeks_len[week];
// update what colles to add
if(mat_halt == 1 || math == 0) {
math = mat_halt-1;
} else {
remaining_to_add++;
math--;
}
if(rotation == ENGLISH) {
rotation = PHYSICS;
} else {
rotation = ENGLISH;
}
remaining_to_add++; // physics/english
// initialize/reset variables
r = rand()%weeklen;
halt = 0;
found = false;
normal_skip = true;
info++;
// info colle
while(info >= info_app) {
if(edt[k+r%weeklen].mat == NOTHING && edt[k+r%weeklen].length == 2) {
// if creneau is empty
// import all colleurs available
colleur* dudes = get_colleurs(chads, len_chads, edt[k+r%weeklen].date, &len_dudes);
len_perm = len_dudes;
// if there are colleurs available
if(len_dudes != 0) {
// randomize the order of colleurs
int* perm = malloc(sizeof(int)*len_perm);
generate_random_perm(perm, len_perm);
// for each one of them, add his colle for selected group pf and only if
// - he is a INFO colleur
// if a colle has been addded, interrupt the for andwhile loops
for(int dude = 0; dude < len_perm*(1-found); dude++) {
if(dudes[perm[dude]].mat == INFO && edt[k+r%weeklen].allow_grps[grp-1] == true) {
add_colle(edt, dudes, grp, k+r%weeklen, perm[dude]);
found = true;
info = 0;
} else if(edt[k+r%weeklen].allow_grps[grp-1] == true) {
normal_skip = false;
}
}
free(perm);
}
free(dudes);
}
if(!found && halt > weeklen) {
info = 0;
*skip_count += (1-normal_skip);
}
r++;
halt++;
}
// reset the variables
r = rand()%weeklen;
found = false;
halt = 0;
normal_skip = true;
// if there is a math colle to add, enter this loop
while(remaining_to_add == 2) {
if(edt[k+r%weeklen].mat == NOTHING && edt[k+r%weeklen].length == 1) {
// if creneau is empty
// import all colleurs available
colleur* dudes = get_colleurs(chads, len_chads, edt[k+r%weeklen].date, &len_dudes);
len_perm = len_dudes;
// if there are colleurs available
if(len_dudes != 0) {
// randomize the order of colleurs
int* perm = malloc(sizeof(int)*len_perm);
generate_random_perm(perm, len_perm);
// for each one of them, add his colle for selected group pf and only if
// - he is a MATH colleur
// - he does not have another colle at the same time (is_overlap)
// if a colle has been addded, interrupt the for andwhile loops
for(int dude = 0; dude < len_perm*(1-found); dude++) {
if(dudes[perm[dude]].mat == MATH && edt[k+r%weeklen].allow_grps[grp-1] == true) {
add_colle(edt, dudes, grp, k+r%weeklen, perm[dude]);
if(is_overlap(edt, len_edt, k+r%weeklen)) {
remove_colle(edt, k+r%weeklen);
} else {
found = true;
remaining_to_add--;
}
}
}
free(perm);
}
free(dudes);
}
if(!found && halt > weeklen) {
remaining_to_add--;
*skip_count += 1;
}
r++;
halt++;
}
// reset the variables
r = rand()%weeklen;
found = false;
halt = 0;
// do it again for physics/english colles
while(remaining_to_add == 1) {
if(edt[k+r%weeklen].mat == NOTHING && edt[k+r%weeklen].length == 1) {
colleur* dudes = get_colleurs(chads, len_chads, edt[k+r%weeklen].date, &len_dudes);
len_perm = len_dudes;
if(len_dudes != 0) {
int* perm = malloc(sizeof(int)*len_perm);
generate_random_perm(perm, len_perm);
math_dude = 0;
for(int dude = 0; dude < len_dudes; dude++) {
if(dudes[dude].mat == MATH) {
math_dude++;
}
}
for(int dude = 0; dude < len_perm*(1-found); dude++) {
if(dudes[perm[dude]].mat == rotation && edt[k+r%weeklen].allow_grps[grp-1] == true) {
add_colle(edt, dudes, grp, k+r%weeklen, perm[dude]);
if(math_dude > free_math_space(edt, len_edt, k+r%weeklen) || is_overlap(edt, len_edt, k+r%weeklen)) {
remove_colle(edt, k+r%weeklen);
} else {
found = true;
remaining_to_add--;
}
}
}
free(perm);
}
free(dudes);
}
if(!found && halt > weeks_len[week]) {
remaining_to_add--;
*skip_count += 1;
}
r++;
halt++;
}
k += weeks_len[week];
remaining_to_add = 0;
}
}
void write_to_file(char* filename, creneau* edt, int len_edt) {
FILE* ptr = fopen(filename, "w");
fprintf(ptr, "hour,day,month,year,length,group,colleur,matiere\n");
for(int i = 0; i < len_edt; i++) {
fprintf(ptr, "%d,%d,%d,%d,%d,%d,%s,", edt[i].date.hour, edt[i].date.day, edt[i].date.month, edt[i].date.year, edt[i].length, edt[i].group, edt[i].name);
if(edt[i].mat == NOTHING) {
fprintf(ptr, "_");
} else if(edt[i].mat == MATH) {
fprintf(ptr, "Maths");
} else if(edt[i].mat == PHYSICS) {
fprintf(ptr, "Physique");
} else if(edt[i].mat == ENGLISH) {
fprintf(ptr, "Anglais");
} else if(edt[i].mat == INFO) {
fprintf(ptr, "Info");
} else if(edt[i].mat == FRENCH) {
fprintf(ptr, "Français");
} else {
fprintf(ptr, "Unknown");
}
fprintf(ptr, "\n");
}
fclose(ptr);
}
int min(int x, int y) {
if(x < y) {
return x;
}
return y;
}
int max(int x, int y) {
if(x > y) {
return x;
}
return y;
}
int score(creneau* edt, int len_edt, int grp, int n_weeks) {
int score = 100;
int dist = 0;
for(int i = 0; i < len_edt; i++) {
for(int j = i+1; j < len_edt; j++) {
if(edt[i].group == grp && edt[j].group == grp) {
dist = date_dist(edt[i].date, edt[j].date);
if(dist == 0) {
score -= 4;
}
/*if(str_equal(edt[i].name, edt[j].name)) {
score -= max(0, 28-dist);
}*/
if(dist == 7 && edt[i].date.hour == edt[j].date.hour) {
score -= 5;
}
if(dist < 5 && edt[i].date.hour == 18 && edt[j].date.hour == 18) {
score -= 5;
}
}
}
}
char** met = malloc(sizeof(char*)*3*n_weeks);
int p = 0;
for(int i = 0; i < len_edt; i++) {
if(edt[i].group == grp) {
met[p] = malloc(sizeof(char)*30);
str_copy(edt[i].name, edt[i].namelen, met[p]);
for(int k = p-1; k >= 0; k--) {
if(str_equal(met[k], met[p])) {
switch(edt[i].mat) {
case MATH:
score -= 12;
break;
case PHYSICS:
score -= 12;
break;
case ENGLISH:
score -= 12;
break;
default:
break;
}
}
}
p++;
}
}
for(int f = 0; f < p; f++) {
free(met[f]);
}
free(met);
return score;
}
int get_colleur_id(colleur* dudes, int n_dudes, char* target) {
for(int i = 0; i < n_dudes; i++) {
if(str_equal(dudes[i].name, target)) {
return i;
}
}
return -1;
}
char* get_name_from_id(colleur* dudes, int n_dudes, int id) {
for(int i = 0; i < n_dudes; i++) {
if(id == dudes[i].id) {
return dudes[i].name;
}
}
return "none";
}
topic get_mat_from_id(colleur* dudes, int n_dudes, int id) {
for(int i = 0; i < n_dudes; i++) {
if(id == dudes[i].id) {
return dudes[i].mat;
}
}
return NOTHING;
}
int** generate_matrix(int lines, int columns, int def) {
int** mat = malloc(sizeof(int*)*lines);
for(int i = 0; i < lines; i++) {
mat[i] = malloc(sizeof(int)*columns);
for(int j = 0; j < columns; j++) {
mat[i][j] = def;
}
}
return mat;
}
void destroy_matrix(int** m, int li) {
for(int i = 0; i < li; i++) {
free(m[i]);
}
free(m);
}
bool retreive_indexes(creneau* edt, int len_edt, int* p1, int* p2, int g1, int g2, char* n1, char* n2, int n_weeks) {
int* indexes_1 = malloc(sizeof(int)*n_weeks);
int* indexes_2 = malloc(sizeof(int)*n_weeks);
int ptr_1 = 0;
int ptr_2 = 0;
for(int i = 0; i < len_edt; i++) {
if(edt[i].group == g1 && str_equal(edt[i].name, n1)) {
indexes_1[ptr_1] = i;
ptr_1++;
} else if(edt[i].group == g2 && str_equal(edt[i].name, n2)) {
indexes_2[ptr_2] = i;
ptr_2++;
}
}
int j = 0;
for(int i = 0; i < ptr_1; i++) {
if(j >= ptr_2) {
free(indexes_1);
free(indexes_2);
return false;
} else {
int friday_1 = get_next_friday(edt, len_edt, edt[indexes_1[i]].date);
int friday_2 = get_next_friday(edt, len_edt, edt[indexes_2[j]].date);
if(friday_1 == friday_2) {
*p1 = indexes_1[i];
*p2 = indexes_2[j];
free(indexes_1);
free(indexes_2);
return true;
} else {
if(friday_1 > friday_2) {
i--;
j++;
}
}
}
}
free(indexes_1);
free(indexes_2);
return false;
}
int** occurencies(creneau* edt, int len_edt, colleur* dudes, int n_groups, int n_colleurs, int n_weeks, bool is_debug) {
int max_occ = 1;
int** res = generate_matrix(n_groups, n_colleurs, 0);
for(int c = 0; c < len_edt; c++) {
if(edt[c].group != 0) {
res[edt[c].group-1][get_colleur_id(dudes, n_colleurs, edt[c].name)] += 1;
}
}
bool halt = false;
for(int it = 0; it < 5*(1-is_debug); it++) {
for(int grp = 0; grp < n_groups; grp++) {
for(int dud = 0; dud < n_colleurs; dud++) {
if(res[grp][dud] > max_occ && get_mat_from_id(dudes, n_colleurs, dud) != INFO) {
for(int grp2 = 0; grp2 < n_groups*(1-halt); grp2++) {
if(grp2 != grp) {
for(int dud2 = 0; dud2 < n_colleurs*(1-halt); dud2++) {
if(dud2 != dud && res[grp2][dud2] > max_occ && res[grp][dud2] < max_occ && res[grp2][dud] < max_occ && get_mat_from_id(dudes, n_colleurs, dud) == get_mat_from_id(dudes, n_colleurs, dud2)) {
int id_src;
int id_dest;
if(retreive_indexes(edt, len_edt, &id_src, &id_dest, grp+1, grp2+1, get_name_from_id(dudes, n_colleurs, dud), get_name_from_id(dudes, n_colleurs, dud2), n_weeks)) {;
if(id_src < 0 || id_dest < 0 || id_src >= len_edt || id_dest >= len_edt) {
printf("Uh oh (%d %d)\n", id_src, id_dest);
exit(1);
}
res[grp][dud] -= 1;
res[grp2][dud2] -= 1;
res[grp2][dud] += 1;
res[grp][dud2] += 1;
edt[id_src].group += edt[id_dest].group;
edt[id_dest].group = edt[id_src].group - edt[id_dest].group;
edt[id_src].group -= edt[id_dest].group;
if(is_overlap_creneau(edt, len_edt, id_src, grp2+1)) {
res[grp][dud] -= 1;
res[grp2][dud2] -= 1;
res[grp2][dud] += 1;
res[grp][dud2] += 1;
edt[id_src].group += edt[id_dest].group;
edt[id_dest].group = edt[id_src].group - edt[id_dest].group;
edt[id_src].group -= edt[id_dest].group;
} else if(is_overlap_creneau(edt, len_edt, id_dest, grp+1)) {
res[grp][dud] -= 1;
res[grp2][dud2] -= 1;
res[grp2][dud] += 1;
res[grp][dud2] += 1;
edt[id_src].group += edt[id_dest].group;
edt[id_dest].group = edt[id_src].group - edt[id_dest].group;
edt[id_src].group -= edt[id_dest].group;
} else {
halt = true;
dud--;
}
}
}
}
}
}
}
halt = false;
}
}
}
return res;
}
void copy_matrix(int** src, int lines, int col, int** dest) {
for(int i = 0; i < lines; i++) {
for(int j = 0; j < col; j++) {
dest[i][j] = src[i][j];
}
}
}
void aux_2(creneau* edt, int len_edt, colleur* chads, int len_chads, int n_groups, int n_weeks, int n_sim, char* outname, int math_halt, int info_app) {
int start = time(NULL);
int* weeks_len = malloc(sizeof(int)*n_weeks);
// this list is used to tell the above code what index of edt it has to go to search for a colle
int ptr = 0;
int current = 1;
for(int k = 1; k < len_edt; k++) {
if(date_dist(edt[k-1].date, edt[k].date) > 1 || k == len_edt-1) {
weeks_len[ptr] = current + (k == len_edt - 1);
current = 0;
ptr++;
}
current++;
}
//printf("----------------------------\n");
int* group_stats = malloc(sizeof(int)*n_groups);
int* group_temp = malloc(sizeof(int)*n_groups);
int max_score = -900000;
int global_min = 0;
int global_skipped = 0;
int screwed_group = 0;
int local_score = 0;
int local_min = 0;
int local_group = 0;
int temp = 0;
int skipped = 0;
int a = 0;
int** occ_data = generate_matrix(n_groups, len_chads, 0);;
info("Testing %d combinations...", n_sim);
printf("\n");
for(int k = 0; k < n_sim*(1 - (max_score == n_groups*100)); k++) {
if(k >= a) {
printf("\x1b[1F");
printf("\x1b[2K");
info("%d%% Completed (current max is %d/%d)", 100*a/n_sim, max_score, 100*n_groups);
a += n_sim/100;
}
local_score = 0;
local_min = 100;
skipped = 0;
for(int i = 0; i < n_groups; i++) {
add_colles_for_group_MP2I(weeks_len, edt, len_edt, chads, len_chads, n_weeks, i+1, (topic)(2+i%2), i%math_halt, i%info_app, &skipped, math_halt, info_app);
}
int** temp_data = occurencies(edt, len_edt, chads, n_groups, len_chads, n_weeks, false);
for(int i = 0; i < n_groups; i++) {
temp = score(edt, len_edt, i+1, n_weeks);
local_score += temp;
group_temp[i] = temp;
if(local_min > temp) {
local_min = temp;
local_group = i+1;
}
}
local_score -= skipped*30;
if(local_score > max_score) {
max_score = local_score;
screwed_group = local_group;
global_min = local_min;
global_skipped = skipped;
for(int p = 0; p < n_groups; p++) {
group_stats[p] = group_temp[p];
}
copy_matrix(temp_data, n_groups, len_chads, occ_data);
write_to_file(outname, edt, len_edt);
}
for(int r = 0; r < len_edt; r++) {
remove_colle(edt, r);
}
destroy_matrix(temp_data, n_groups);
}
printf("\x1b[1F");
printf("\x1b[2K");
if(max_score == 100*n_groups) {
info("Interrupting early due to a perfect score achieved");
} else {
info("100%% Completed, best score is %d/%d (without skip penalty) with %d skipped colle(s)", max_score+global_skipped*30, 100*n_groups, global_skipped);
info("Most screwed group is %d with a score of %d/100", screwed_group, global_min);
debug("Stats for all groups are :");
for(int i = 0; i < n_groups; i++) {
debug("Group %d : %d/100", i+1, group_stats[i]);
}
}
int end = time(NULL);
printf("\n");
info("Here is all data regarding colles occurencies :");
for(int k = 0; k < n_groups; k++) {
printf("Group %d : ", (k+1)%10);
print_arr(occ_data[k], len_chads);
}
info("Took %ds to find", end-start);
free(group_stats);
free(group_temp);
free(weeks_len);
destroy_matrix(occ_data, n_groups);
}

View File

@ -1,218 +0,0 @@
hour,day,month,year,length,group,colleur,matiere
12,22,4,2024,1,12,Chevalier,Physique
12,22,4,2024,2,0,none,_
13,22,4,2024,2,0,none,_
14,23,4,2024,1,2,Chevalier,Physique
14,23,4,2024,1,3,Belagoune,Anglais
14,23,4,2024,1,11,Mullaert,Maths
17,23,4,2024,1,4,Colin,Physique
17,23,4,2024,1,5,Herbaut,Anglais
17,23,4,2024,1,6,Chevalier,Physique
17,23,4,2024,1,9,Belagoune,Anglais
18,23,4,2024,1,7,Belagoune,Anglais
18,23,4,2024,1,12,Rapin,Maths
14,24,4,2024,2,12,Rouvroy,Info
14,24,4,2024,2,6,Rouvroy,Info
14,24,4,2024,2,0,none,_
14,24,4,2024,1,1,Le_Gouriellec,Anglais
14,24,4,2024,1,6,Carpintero,Maths
14,24,4,2024,1,9,Boully,Maths
15,24,4,2024,1,2,Carpintero,Maths
15,24,4,2024,1,11,Le_Gouriellec,Anglais
15,24,4,2024,1,15,Boully,Maths
16,24,4,2024,1,13,Mann,Anglais
17,24,4,2024,1,14,Poupy,Physique
17,24,4,2024,1,15,Mann,Anglais
18,24,4,2024,1,10,Poupy,Physique
18,25,4,2024,1,3,Mullaert,Maths
18,25,4,2024,1,14,Rapin,Maths
18,25,4,2024,1,8,De_Roux,Physique
16,26,4,2024,1,0,none,_
17,26,4,2024,1,5,Oubaha,Maths
18,26,4,2024,1,8,Oubaha,Maths
12,29,4,2024,1,11,Chevalier,Physique
12,29,4,2024,2,5,Jospin,Info
13,29,4,2024,2,11,Jospin,Info
14,30,4,2024,1,1,Mullaert,Maths
14,30,4,2024,1,6,Belagoune,Anglais
14,30,4,2024,1,5,Chevalier,Physique
17,30,4,2024,1,10,Herbaut,Anglais
17,30,4,2024,1,3,Colin,Physique
17,30,4,2024,1,14,Belagoune,Anglais
17,30,4,2024,1,15,Chevalier,Physique
18,30,4,2024,1,13,Rapin,Maths
18,30,4,2024,1,8,Belagoune,Anglais
14,1,5,2024,2,0,none,_
14,1,5,2024,2,0,none,_
14,1,5,2024,2,0,none,_
14,1,5,2024,1,3,Boully,Maths
14,1,5,2024,1,2,Le_Gouriellec,Anglais
14,1,5,2024,1,15,Carpintero,Maths
15,1,5,2024,1,7,Carpintero,Maths
15,1,5,2024,1,12,Le_Gouriellec,Anglais
15,1,5,2024,1,12,Boully,Maths
16,1,5,2024,1,0,none,_
17,1,5,2024,1,1,Poupy,Physique
17,1,5,2024,1,4,Mann,Anglais
18,1,5,2024,1,13,Poupy,Physique
18,2,5,2024,1,6,Rapin,Maths
18,2,5,2024,1,7,De_Roux,Physique
18,2,5,2024,1,9,Mullaert,Maths
16,3,5,2024,1,9,Chibani,Physique
17,3,5,2024,1,10,Oubaha,Maths
18,3,5,2024,1,4,Oubaha,Maths
12,6,5,2024,1,0,none,_
12,6,5,2024,2,4,Jospin,Info
13,6,5,2024,2,0,none,_
14,7,5,2024,1,8,Mullaert,Maths
14,7,5,2024,1,3,Belagoune,Anglais
14,7,5,2024,1,4,Chevalier,Physique
17,7,5,2024,1,13,Herbaut,Anglais
17,7,5,2024,1,10,Colin,Physique
17,7,5,2024,1,1,Belagoune,Anglais
17,7,5,2024,1,2,Chevalier,Physique
18,7,5,2024,1,4,Rapin,Maths
18,7,5,2024,1,15,Belagoune,Anglais
14,8,5,2024,2,0,none,_
14,8,5,2024,2,10,Rouvroy,Info
14,8,5,2024,2,0,none,_
14,8,5,2024,1,1,Boully,Maths
14,8,5,2024,1,10,Carpintero,Maths
14,8,5,2024,1,11,Le_Gouriellec,Anglais
15,8,5,2024,1,5,Le_Gouriellec,Anglais
15,8,5,2024,1,14,Carpintero,Maths
15,8,5,2024,1,13,Boully,Maths
16,8,5,2024,1,9,Mann,Anglais
17,8,5,2024,1,7,Mann,Anglais
17,8,5,2024,1,8,Poupy,Physique
18,8,5,2024,1,12,Poupy,Physique
18,9,5,2024,1,5,Mullaert,Maths
18,9,5,2024,1,2,Rapin,Maths
18,9,5,2024,1,14,De_Roux,Physique
16,10,5,2024,1,6,Chibani,Physique
17,10,5,2024,1,7,Oubaha,Maths
18,10,5,2024,1,11,Oubaha,Maths
12,13,5,2024,1,1,Chevalier,Physique
12,13,5,2024,2,15,Jospin,Info
13,13,5,2024,2,0,none,_
14,14,5,2024,1,6,Mullaert,Maths
14,14,5,2024,1,7,Chevalier,Physique
14,14,5,2024,1,10,Belagoune,Anglais
17,14,5,2024,1,13,Colin,Physique
17,14,5,2024,1,2,Belagoune,Anglais
17,14,5,2024,1,6,Herbaut,Anglais
17,14,5,2024,1,15,Chevalier,Physique
18,14,5,2024,1,9,Rapin,Maths
18,14,5,2024,1,12,Belagoune,Anglais
14,15,5,2024,2,9,Rouvroy,Info
14,15,5,2024,2,0,none,_
14,15,5,2024,2,0,none,_
14,15,5,2024,1,3,Carpintero,Maths
14,15,5,2024,1,4,Le_Gouriellec,Anglais
14,15,5,2024,1,5,Boully,Maths
15,15,5,2024,1,11,Carpintero,Maths
15,15,5,2024,1,8,Le_Gouriellec,Anglais
15,15,5,2024,1,14,Boully,Maths
16,15,5,2024,1,14,Mann,Anglais
17,15,5,2024,1,5,Poupy,Physique
17,15,5,2024,1,0,none,_
18,15,5,2024,1,3,Poupy,Physique
18,16,5,2024,1,9,De_Roux,Physique
18,16,5,2024,1,8,Rapin,Maths
18,16,5,2024,1,12,Mullaert,Maths
16,17,5,2024,1,11,Chibani,Physique
17,17,5,2024,1,2,Oubaha,Maths
18,17,5,2024,1,15,Oubaha,Maths
12,20,5,2024,1,8,Chevalier,Physique
12,20,5,2024,2,8,Jospin,Info
13,20,5,2024,2,14,Jospin,Info
14,21,5,2024,1,1,Belagoune,Anglais
14,21,5,2024,1,14,Chevalier,Physique
14,21,5,2024,1,15,Mullaert,Maths
17,21,5,2024,1,3,Herbaut,Anglais
17,21,5,2024,1,0,none,_
17,21,5,2024,1,5,Belagoune,Anglais
17,21,5,2024,1,10,Chevalier,Physique
18,21,5,2024,1,1,Rapin,Maths
18,21,5,2024,1,13,Belagoune,Anglais
14,22,5,2024,2,0,none,_
14,22,5,2024,2,0,none,_
14,22,5,2024,2,0,none,_
14,22,5,2024,1,13,Carpintero,Maths
14,22,5,2024,1,6,Boully,Maths
14,22,5,2024,1,7,Le_Gouriellec,Anglais
15,22,5,2024,1,7,Boully,Maths
15,22,5,2024,1,9,Le_Gouriellec,Anglais
15,22,5,2024,1,4,Carpintero,Maths
16,22,5,2024,1,11,Mann,Anglais
17,22,5,2024,1,2,Poupy,Physique
17,22,5,2024,1,15,Mann,Anglais
18,22,5,2024,1,4,Poupy,Physique
18,23,5,2024,1,10,Rapin,Maths
18,23,5,2024,1,12,Mullaert,Maths
18,23,5,2024,1,6,De_Roux,Physique
16,24,5,2024,1,12,Chibani,Physique
17,24,5,2024,1,3,Oubaha,Maths
18,24,5,2024,1,9,Oubaha,Maths
12,27,5,2024,1,1,Chevalier,Physique
12,27,5,2024,2,7,Jospin,Info
13,27,5,2024,2,13,Jospin,Info
14,28,5,2024,1,2,Belagoune,Anglais
14,28,5,2024,1,3,Chevalier,Physique
14,28,5,2024,1,4,Mullaert,Maths
17,28,5,2024,1,12,Herbaut,Anglais
17,28,5,2024,1,9,Colin,Physique
17,28,5,2024,1,13,Chevalier,Physique
17,28,5,2024,1,4,Belagoune,Anglais
18,28,5,2024,1,7,Rapin,Maths
18,28,5,2024,1,10,Belagoune,Anglais
14,29,5,2024,2,0,none,_
14,29,5,2024,2,0,none,_
14,29,5,2024,2,0,none,_
14,29,5,2024,1,2,Boully,Maths
14,29,5,2024,1,1,Carpintero,Maths
14,29,5,2024,1,6,Le_Gouriellec,Anglais
15,29,5,2024,1,5,Boully,Maths
15,29,5,2024,1,8,Carpintero,Maths
15,29,5,2024,1,14,Le_Gouriellec,Anglais
16,29,5,2024,1,0,none,_
17,29,5,2024,1,7,Poupy,Physique
17,29,5,2024,1,8,Mann,Anglais
18,29,5,2024,1,11,Poupy,Physique
18,30,5,2024,1,10,Mullaert,Maths
18,30,5,2024,1,5,De_Roux,Physique
18,30,5,2024,1,11,Rapin,Maths
16,31,5,2024,1,15,Chibani,Physique
17,31,5,2024,1,13,Oubaha,Maths
18,31,5,2024,1,14,Oubaha,Maths
12,3,6,2024,1,14,Chevalier,Physique
12,3,6,2024,2,6,Jospin,Info
13,3,6,2024,2,12,Jospin,Info
14,4,6,2024,1,2,Mullaert,Maths
14,4,6,2024,1,5,Belagoune,Anglais
14,4,6,2024,1,8,Chevalier,Physique
17,4,6,2024,1,9,Herbaut,Anglais
17,4,6,2024,1,11,Belagoune,Anglais
17,4,6,2024,1,0,none,_
17,4,6,2024,1,6,Colin,Physique
18,4,6,2024,1,5,Rapin,Maths
18,4,6,2024,1,7,Belagoune,Anglais
14,5,6,2024,2,0,none,_
14,5,6,2024,2,0,none,_
14,5,6,2024,2,0,none,_
14,5,6,2024,1,12,Carpintero,Maths
14,5,6,2024,1,15,Le_Gouriellec,Anglais
14,5,6,2024,1,8,Boully,Maths
15,5,6,2024,1,9,Carpintero,Maths
15,5,6,2024,1,11,Boully,Maths
15,5,6,2024,1,13,Le_Gouriellec,Anglais
16,5,6,2024,1,3,Mann,Anglais
17,5,6,2024,1,4,Poupy,Physique
17,5,6,2024,1,1,Mann,Anglais
18,5,6,2024,1,12,Poupy,Physique
18,6,6,2024,1,3,Rapin,Maths
18,6,6,2024,1,10,De_Roux,Physique
18,6,6,2024,1,14,Mullaert,Maths
16,7,6,2024,1,2,Chibani,Physique
17,7,6,2024,1,6,Oubaha,Maths
18,7,6,2024,1,15,Oubaha,Maths
1 hour day month year length group colleur matiere
2 12 22 4 2024 1 12 Chevalier Physique
3 12 22 4 2024 2 0 none _
4 13 22 4 2024 2 0 none _
5 14 23 4 2024 1 2 Chevalier Physique
6 14 23 4 2024 1 3 Belagoune Anglais
7 14 23 4 2024 1 11 Mullaert Maths
8 17 23 4 2024 1 4 Colin Physique
9 17 23 4 2024 1 5 Herbaut Anglais
10 17 23 4 2024 1 6 Chevalier Physique
11 17 23 4 2024 1 9 Belagoune Anglais
12 18 23 4 2024 1 7 Belagoune Anglais
13 18 23 4 2024 1 12 Rapin Maths
14 14 24 4 2024 2 12 Rouvroy Info
15 14 24 4 2024 2 6 Rouvroy Info
16 14 24 4 2024 2 0 none _
17 14 24 4 2024 1 1 Le_Gouriellec Anglais
18 14 24 4 2024 1 6 Carpintero Maths
19 14 24 4 2024 1 9 Boully Maths
20 15 24 4 2024 1 2 Carpintero Maths
21 15 24 4 2024 1 11 Le_Gouriellec Anglais
22 15 24 4 2024 1 15 Boully Maths
23 16 24 4 2024 1 13 Mann Anglais
24 17 24 4 2024 1 14 Poupy Physique
25 17 24 4 2024 1 15 Mann Anglais
26 18 24 4 2024 1 10 Poupy Physique
27 18 25 4 2024 1 3 Mullaert Maths
28 18 25 4 2024 1 14 Rapin Maths
29 18 25 4 2024 1 8 De_Roux Physique
30 16 26 4 2024 1 0 none _
31 17 26 4 2024 1 5 Oubaha Maths
32 18 26 4 2024 1 8 Oubaha Maths
33 12 29 4 2024 1 11 Chevalier Physique
34 12 29 4 2024 2 5 Jospin Info
35 13 29 4 2024 2 11 Jospin Info
36 14 30 4 2024 1 1 Mullaert Maths
37 14 30 4 2024 1 6 Belagoune Anglais
38 14 30 4 2024 1 5 Chevalier Physique
39 17 30 4 2024 1 10 Herbaut Anglais
40 17 30 4 2024 1 3 Colin Physique
41 17 30 4 2024 1 14 Belagoune Anglais
42 17 30 4 2024 1 15 Chevalier Physique
43 18 30 4 2024 1 13 Rapin Maths
44 18 30 4 2024 1 8 Belagoune Anglais
45 14 1 5 2024 2 0 none _
46 14 1 5 2024 2 0 none _
47 14 1 5 2024 2 0 none _
48 14 1 5 2024 1 3 Boully Maths
49 14 1 5 2024 1 2 Le_Gouriellec Anglais
50 14 1 5 2024 1 15 Carpintero Maths
51 15 1 5 2024 1 7 Carpintero Maths
52 15 1 5 2024 1 12 Le_Gouriellec Anglais
53 15 1 5 2024 1 12 Boully Maths
54 16 1 5 2024 1 0 none _
55 17 1 5 2024 1 1 Poupy Physique
56 17 1 5 2024 1 4 Mann Anglais
57 18 1 5 2024 1 13 Poupy Physique
58 18 2 5 2024 1 6 Rapin Maths
59 18 2 5 2024 1 7 De_Roux Physique
60 18 2 5 2024 1 9 Mullaert Maths
61 16 3 5 2024 1 9 Chibani Physique
62 17 3 5 2024 1 10 Oubaha Maths
63 18 3 5 2024 1 4 Oubaha Maths
64 12 6 5 2024 1 0 none _
65 12 6 5 2024 2 4 Jospin Info
66 13 6 5 2024 2 0 none _
67 14 7 5 2024 1 8 Mullaert Maths
68 14 7 5 2024 1 3 Belagoune Anglais
69 14 7 5 2024 1 4 Chevalier Physique
70 17 7 5 2024 1 13 Herbaut Anglais
71 17 7 5 2024 1 10 Colin Physique
72 17 7 5 2024 1 1 Belagoune Anglais
73 17 7 5 2024 1 2 Chevalier Physique
74 18 7 5 2024 1 4 Rapin Maths
75 18 7 5 2024 1 15 Belagoune Anglais
76 14 8 5 2024 2 0 none _
77 14 8 5 2024 2 10 Rouvroy Info
78 14 8 5 2024 2 0 none _
79 14 8 5 2024 1 1 Boully Maths
80 14 8 5 2024 1 10 Carpintero Maths
81 14 8 5 2024 1 11 Le_Gouriellec Anglais
82 15 8 5 2024 1 5 Le_Gouriellec Anglais
83 15 8 5 2024 1 14 Carpintero Maths
84 15 8 5 2024 1 13 Boully Maths
85 16 8 5 2024 1 9 Mann Anglais
86 17 8 5 2024 1 7 Mann Anglais
87 17 8 5 2024 1 8 Poupy Physique
88 18 8 5 2024 1 12 Poupy Physique
89 18 9 5 2024 1 5 Mullaert Maths
90 18 9 5 2024 1 2 Rapin Maths
91 18 9 5 2024 1 14 De_Roux Physique
92 16 10 5 2024 1 6 Chibani Physique
93 17 10 5 2024 1 7 Oubaha Maths
94 18 10 5 2024 1 11 Oubaha Maths
95 12 13 5 2024 1 1 Chevalier Physique
96 12 13 5 2024 2 15 Jospin Info
97 13 13 5 2024 2 0 none _
98 14 14 5 2024 1 6 Mullaert Maths
99 14 14 5 2024 1 7 Chevalier Physique
100 14 14 5 2024 1 10 Belagoune Anglais
101 17 14 5 2024 1 13 Colin Physique
102 17 14 5 2024 1 2 Belagoune Anglais
103 17 14 5 2024 1 6 Herbaut Anglais
104 17 14 5 2024 1 15 Chevalier Physique
105 18 14 5 2024 1 9 Rapin Maths
106 18 14 5 2024 1 12 Belagoune Anglais
107 14 15 5 2024 2 9 Rouvroy Info
108 14 15 5 2024 2 0 none _
109 14 15 5 2024 2 0 none _
110 14 15 5 2024 1 3 Carpintero Maths
111 14 15 5 2024 1 4 Le_Gouriellec Anglais
112 14 15 5 2024 1 5 Boully Maths
113 15 15 5 2024 1 11 Carpintero Maths
114 15 15 5 2024 1 8 Le_Gouriellec Anglais
115 15 15 5 2024 1 14 Boully Maths
116 16 15 5 2024 1 14 Mann Anglais
117 17 15 5 2024 1 5 Poupy Physique
118 17 15 5 2024 1 0 none _
119 18 15 5 2024 1 3 Poupy Physique
120 18 16 5 2024 1 9 De_Roux Physique
121 18 16 5 2024 1 8 Rapin Maths
122 18 16 5 2024 1 12 Mullaert Maths
123 16 17 5 2024 1 11 Chibani Physique
124 17 17 5 2024 1 2 Oubaha Maths
125 18 17 5 2024 1 15 Oubaha Maths
126 12 20 5 2024 1 8 Chevalier Physique
127 12 20 5 2024 2 8 Jospin Info
128 13 20 5 2024 2 14 Jospin Info
129 14 21 5 2024 1 1 Belagoune Anglais
130 14 21 5 2024 1 14 Chevalier Physique
131 14 21 5 2024 1 15 Mullaert Maths
132 17 21 5 2024 1 3 Herbaut Anglais
133 17 21 5 2024 1 0 none _
134 17 21 5 2024 1 5 Belagoune Anglais
135 17 21 5 2024 1 10 Chevalier Physique
136 18 21 5 2024 1 1 Rapin Maths
137 18 21 5 2024 1 13 Belagoune Anglais
138 14 22 5 2024 2 0 none _
139 14 22 5 2024 2 0 none _
140 14 22 5 2024 2 0 none _
141 14 22 5 2024 1 13 Carpintero Maths
142 14 22 5 2024 1 6 Boully Maths
143 14 22 5 2024 1 7 Le_Gouriellec Anglais
144 15 22 5 2024 1 7 Boully Maths
145 15 22 5 2024 1 9 Le_Gouriellec Anglais
146 15 22 5 2024 1 4 Carpintero Maths
147 16 22 5 2024 1 11 Mann Anglais
148 17 22 5 2024 1 2 Poupy Physique
149 17 22 5 2024 1 15 Mann Anglais
150 18 22 5 2024 1 4 Poupy Physique
151 18 23 5 2024 1 10 Rapin Maths
152 18 23 5 2024 1 12 Mullaert Maths
153 18 23 5 2024 1 6 De_Roux Physique
154 16 24 5 2024 1 12 Chibani Physique
155 17 24 5 2024 1 3 Oubaha Maths
156 18 24 5 2024 1 9 Oubaha Maths
157 12 27 5 2024 1 1 Chevalier Physique
158 12 27 5 2024 2 7 Jospin Info
159 13 27 5 2024 2 13 Jospin Info
160 14 28 5 2024 1 2 Belagoune Anglais
161 14 28 5 2024 1 3 Chevalier Physique
162 14 28 5 2024 1 4 Mullaert Maths
163 17 28 5 2024 1 12 Herbaut Anglais
164 17 28 5 2024 1 9 Colin Physique
165 17 28 5 2024 1 13 Chevalier Physique
166 17 28 5 2024 1 4 Belagoune Anglais
167 18 28 5 2024 1 7 Rapin Maths
168 18 28 5 2024 1 10 Belagoune Anglais
169 14 29 5 2024 2 0 none _
170 14 29 5 2024 2 0 none _
171 14 29 5 2024 2 0 none _
172 14 29 5 2024 1 2 Boully Maths
173 14 29 5 2024 1 1 Carpintero Maths
174 14 29 5 2024 1 6 Le_Gouriellec Anglais
175 15 29 5 2024 1 5 Boully Maths
176 15 29 5 2024 1 8 Carpintero Maths
177 15 29 5 2024 1 14 Le_Gouriellec Anglais
178 16 29 5 2024 1 0 none _
179 17 29 5 2024 1 7 Poupy Physique
180 17 29 5 2024 1 8 Mann Anglais
181 18 29 5 2024 1 11 Poupy Physique
182 18 30 5 2024 1 10 Mullaert Maths
183 18 30 5 2024 1 5 De_Roux Physique
184 18 30 5 2024 1 11 Rapin Maths
185 16 31 5 2024 1 15 Chibani Physique
186 17 31 5 2024 1 13 Oubaha Maths
187 18 31 5 2024 1 14 Oubaha Maths
188 12 3 6 2024 1 14 Chevalier Physique
189 12 3 6 2024 2 6 Jospin Info
190 13 3 6 2024 2 12 Jospin Info
191 14 4 6 2024 1 2 Mullaert Maths
192 14 4 6 2024 1 5 Belagoune Anglais
193 14 4 6 2024 1 8 Chevalier Physique
194 17 4 6 2024 1 9 Herbaut Anglais
195 17 4 6 2024 1 11 Belagoune Anglais
196 17 4 6 2024 1 0 none _
197 17 4 6 2024 1 6 Colin Physique
198 18 4 6 2024 1 5 Rapin Maths
199 18 4 6 2024 1 7 Belagoune Anglais
200 14 5 6 2024 2 0 none _
201 14 5 6 2024 2 0 none _
202 14 5 6 2024 2 0 none _
203 14 5 6 2024 1 12 Carpintero Maths
204 14 5 6 2024 1 15 Le_Gouriellec Anglais
205 14 5 6 2024 1 8 Boully Maths
206 15 5 6 2024 1 9 Carpintero Maths
207 15 5 6 2024 1 11 Boully Maths
208 15 5 6 2024 1 13 Le_Gouriellec Anglais
209 16 5 6 2024 1 3 Mann Anglais
210 17 5 6 2024 1 4 Poupy Physique
211 17 5 6 2024 1 1 Mann Anglais
212 18 5 6 2024 1 12 Poupy Physique
213 18 6 6 2024 1 3 Rapin Maths
214 18 6 6 2024 1 10 De_Roux Physique
215 18 6 6 2024 1 14 Mullaert Maths
216 16 7 6 2024 1 2 Chibani Physique
217 17 7 6 2024 1 6 Oubaha Maths
218 18 7 6 2024 1 15 Oubaha Maths

19
src/algorithm.c Normal file → Executable file
View File

@ -215,6 +215,8 @@ void add_colles_for_group_MP2I(int* weeks_len, creneau* edt, int len_edt, colleu
int math_dude = 0; // length of colleur*
int weeklen;
bool normal_skip = true;
for(int week = 0; week < n_weeks; week++) {
weeklen = weeks_len[week];
@ -237,6 +239,7 @@ void add_colles_for_group_MP2I(int* weeks_len, creneau* edt, int len_edt, colleu
r = rand()%weeklen;
halt = 0;
found = false;
normal_skip = true;
info++;
// info colle
@ -255,14 +258,15 @@ void add_colles_for_group_MP2I(int* weeks_len, creneau* edt, int len_edt, colleu
generate_random_perm(perm, len_perm);
// for each one of them, add his colle for selected group pf and only if
// - he is a MATH colleur
// - he does not have another colle at the same time (is_overlap)
// - he is a INFO colleur
// if a colle has been addded, interrupt the for andwhile loops
for(int dude = 0; dude < len_perm*(1-found); dude++) {
if(dudes[perm[dude]].mat == INFO && edt[k+r%weeklen].allow_grps[grp-1] == true ) {
if(dudes[perm[dude]].mat == INFO && edt[k+r%weeklen].allow_grps[grp-1] == true) {
add_colle(edt, dudes, grp, k+r%weeklen, perm[dude]);
found = true;
info = 0;
} else if(edt[k+r%weeklen].allow_grps[grp-1] == true) {
normal_skip = false;
}
}
free(perm);
@ -271,7 +275,7 @@ void add_colles_for_group_MP2I(int* weeks_len, creneau* edt, int len_edt, colleu
}
if(!found && halt > weeklen) {
info = 0;
*skip_count += 1;
*skip_count += (1-normal_skip);
}
r++;
halt++;
@ -280,6 +284,7 @@ void add_colles_for_group_MP2I(int* weeks_len, creneau* edt, int len_edt, colleu
r = rand()%weeklen;
found = false;
halt = 0;
normal_skip = true;
// if there is a math colle to add, enter this loop
while(remaining_to_add == 2) {
@ -302,7 +307,7 @@ void add_colles_for_group_MP2I(int* weeks_len, creneau* edt, int len_edt, colleu
// - he does not have another colle at the same time (is_overlap)
// if a colle has been addded, interrupt the for andwhile loops
for(int dude = 0; dude < len_perm*(1-found); dude++) {
if(dudes[perm[dude]].mat == MATH) {
if(dudes[perm[dude]].mat == MATH && edt[k+r%weeklen].allow_grps[grp-1] == true) {
add_colle(edt, dudes, grp, k+r%weeklen, perm[dude]);
if(is_overlap(edt, len_edt, k+r%weeklen)) {
remove_colle(edt, k+r%weeklen);
@ -343,7 +348,7 @@ void add_colles_for_group_MP2I(int* weeks_len, creneau* edt, int len_edt, colleu
}
}
for(int dude = 0; dude < len_perm*(1-found); dude++) {
if(dudes[perm[dude]].mat == rotation) {
if(dudes[perm[dude]].mat == rotation && edt[k+r%weeklen].allow_grps[grp-1] == true) {
add_colle(edt, dudes, grp, k+r%weeklen, perm[dude]);
if(math_dude > free_math_space(edt, len_edt, k+r%weeklen) || is_overlap(edt, len_edt, k+r%weeklen)) {
remove_colle(edt, k+r%weeklen);
@ -376,7 +381,7 @@ void write_to_file(char* filename, creneau* edt, int len_edt) {
for(int i = 0; i < len_edt; i++) {
fprintf(ptr, "%d,%d,%d,%d,%d,%d,%s,", edt[i].date.hour, edt[i].date.day, edt[i].date.month, edt[i].date.year, edt[i].length, edt[i].group, edt[i].name);
if(edt[i].mat == NOTHING) {
fprintf(ptr, "_");
fprintf(ptr, "none");
} else if(edt[i].mat == MATH) {
fprintf(ptr, "Maths");
} else if(edt[i].mat == PHYSICS) {

0
src/algorithm.h Normal file → Executable file
View File

0
src/display.c Normal file → Executable file
View File

0
src/display.h Normal file → Executable file
View File

0
src/logger.c Normal file → Executable file
View File

0
src/logger.h Normal file → Executable file
View File

13
src/main.c Normal file → Executable file
View File

@ -51,11 +51,11 @@ int main(int argc, char **argv) {
print_help();
exit(0);
}
else if (argc==12 && argv[1][0]!='-')
else if (argc==11 && argv[1][0]!='-')
{
offset=0;
}
else if (argc==13 && argv[1][0]=='-')
else if (argc==12 && argv[1][0]=='-')
{
offset=1;
@ -78,7 +78,7 @@ int main(int argc, char **argv) {
}
}
else {
fprintf(stderr, "Usage: %s [-qvh] <creneaux> <n_creneaux> <colleurs> <n_colleurs> <n_weeks> <n_groups> <n_iters> <output> <math_rest> <info_occ> <blacklist>\n", argv[0]);
fprintf(stderr, "Usage: %s [-qvh] <creneaux> <n_creneaux> <colleurs> <n_colleurs> <n_weeks> <n_groups> <n_iters> <output> <math_rest> <info_occ>\n", argv[0]);
exit(1);
}
@ -93,7 +93,6 @@ int main(int argc, char **argv) {
char* path_output = argv[8+offset];
int math_i = str_to_int(argv[9+offset]);
int info_i = str_to_int(argv[10+offset]);
char* blacklist_path = argv[11+offset];
if (quiet) {
create_logger("colloscope.log", LOG_WARN);
@ -103,6 +102,8 @@ int main(int argc, char **argv) {
create_logger("colloscope.log", LOG_INFO);
}
//info("%d %d %d %d", n_creneaux, n_colleurs, n_weeks, n_groups);
info("Starting");
srand(time(NULL));
@ -113,8 +114,8 @@ int main(int argc, char **argv) {
//colleur* dudes = import_colleurs("some_data.txt", 13, len_creneau);
colleur* dudes = import_colleurs_oneweek(path_colleurs, n_colleurs, n_weeks, n_creneaux);
import_tds(edt, len_edt, n_creneaux, blacklist_path);
import_tds(edt, len_edt, n_creneaux, "S3-tds.txt");
debug("Entries are : ");
debug("Creneaux filename : %s", path_creneaux);
debug("Number of creneaux (for one week) : %d", n_creneaux);

35
src/structure.c Normal file → Executable file
View File

@ -519,7 +519,7 @@ void import_tds(creneau* edt, int len_edt, int len_oneweek, char* filename) {
int current = 0;
int place = 0;
char method = 'A';
char method;
int buffer = 0;
@ -551,34 +551,9 @@ void import_tds(creneau* edt, int len_edt, int len_oneweek, char* filename) {
k++;
os = 1;
}
} else if(method == 'T') {
int k = 0;
int os = 1;
edt[edtptr + k*len_oneweek].allow_grps[buffer-1] = false;
while(equal_d(edt[edtptr + k*len_oneweek].date, edt[edtptr + k*len_oneweek + os].date)) {
//info("[%d, %d]", buffer, edtptr + k*len_oneweek + os);
edt[edtptr + k*len_oneweek + os].allow_grps[buffer-1] = false;
os++;
}
k = 1;
os = 1;
while(edtptr + k*len_oneweek >= 0 && edtptr + k*len_oneweek < len_edt) {
//info("[%d, %d]", buffer, edtptr + k*len_oneweek);
//usleep(1000000);
edt[edtptr + k*len_oneweek].allow_grps[buffer-1] = edt[edtptr + (k-1)*len_oneweek].allow_grps[buffer-1];
while(equal_d(edt[edtptr + k*len_oneweek].date, edt[edtptr + k*len_oneweek + os].date)) {
//info("[%d, %d]", buffer, edtptr + k*len_oneweek + os);
edt[edtptr + k*len_oneweek + os].allow_grps[buffer-1] = edt[edtptr + (k-1)*len_oneweek + os].allow_grps[buffer-1];
os++;
}
k++;
os = 1;
}
} else {
fprintf(stderr, "Warning : unknown method (%c) detected in TD\n", method);
fatal("Unknown method %d. Check if the method used is valid, or ask a dev to fix it ", method);
exit(1);
}
}
current++;
@ -593,14 +568,14 @@ void import_tds(creneau* edt, int len_edt, int len_oneweek, char* filename) {
} else {
d.year = buffer;
current = 1;
c = fgetc(ptr);
method = c;
}
place++;
buffer = 0;
} else if((int)(c) >= 48 && (int)(c) <= 57) {
buffer *= 10;
buffer += (int)(c) - 48;
} else if(current == 1) {
method = c;
}
c = fgetc(ptr);
}

0
src/structure.h Normal file → Executable file
View File

View File

@ -1,585 +0,0 @@
/*
* Colloscope - A program that generates a colloscope for French 'classes prépas'
* Copyright (C) 2024 Alexandre Aboujaib
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#include <stdio.h>
#include <stdlib.h>
#include <assert.h>
#include <stdbool.h>
#include <unistd.h>
#include "logger.h"
#include "structure.h"
//static int width = 1200;
//static int height = 900;
int date_dist(date d1, date d2) { /* returns distance between d1 and d2 in days
if d2 is sooner than d1, it will return -1 */
if(d2.month == d1.month && d2.year == d1.year) {
if(d2.day < d1.day) {
return -1;
}
return d2.day - d1.day;
} else {
int is_31 = 0;
if(d1.month == 1 || d1.month == 3 || d1.month == 5 || d1.month == 7 || d1.month == 8 || d1.month == 10 || d1.month == 12) {
is_31 = 1;
} else {
is_31 = (d1.month == 2)*(-2) + (d1.month == 2 && d1.year%4 == 0 && d1.year%100 != 0);
}
if(d2.month - d1.month < 0 && d2.year <= d1.year) {
return -1;
} else if(d2.month - d1.month == 1 && d2.year == d1.year) {
return d2.day + (30 + is_31 - d1.day);
} else {
date copy;
copy.day = d1.day;
copy.month = d1.month;
copy.year = d1.year;
copy.month = (copy.month + 1);
if(copy.month == 13) {
copy.month = 1;
copy.year += 1;
}
return (30 + is_31 + date_dist(copy, d2));
}
}
}
bool is_sorted(creneau* edt, int len) {
for(int i = 1; i < len; i++) {
if(date_dist(edt[i-1].date, edt[i].date) == -1) {
warn("Anomaly detected at lane %d (dates are not sorted in ascending order) :", i);
warn("%d %d %d %d", edt[i-1].date.hour, edt[i-1].date.day, edt[i-1].date.month, edt[i-1].date.year);
warn("%d %d %d %d", edt[i].date.hour, edt[i].date.day, edt[i].date.month, edt[i].date.year);
warn("%d %d %d %d", edt[i+1].date.hour, edt[i+1].date.day, edt[i+1].date.month, edt[i+1].date.year);
return false;
}
}
info("No problem detected");
return true;
}
creneau* import_creneaux(char* filename, int size) {
// import creneau data from a file
// see file.txt for an example
FILE* ptr = fopen(filename, "r");
char c = fgetc(ptr);
creneau* edt = malloc(sizeof(creneau)*size);
int i = 0;
int to_fill = 0;
int buffer = 0;
while(c != EOF && c != '$') {
if((int)(c) >= 48 && (int)(c) <= 57) {
buffer *= 10;
buffer += (int)(c) - 48;
} else {
if(to_fill == 0) {
//printf("%d\n", i);
edt[i].date.hour = buffer;
edt[i].group = 0;
edt[i].name = malloc(sizeof(char)*35);
edt[i].name[0] = 'n';
edt[i].name[1] = 'o';
edt[i].name[2] = 'n';
edt[i].name[3] = 'e';
edt[i].name[4] = '\0';
edt[i].namelen = 4;
edt[i].mat = NOTHING;
edt[i].salle.building = 'N';
edt[i].salle.id = 0;
edt[i].length = 1;
} else if(to_fill == 1) {
edt[i].date.day = buffer;
} else if(to_fill == 2) {
edt[i].date.month = buffer;
} else if(to_fill == 3) {
edt[i].date.year = buffer;
} else {
edt[i].length++;
}
to_fill++;
buffer = 0;
if(c == '\n') {
i++;
to_fill = 0;
}
}
c = fgetc(ptr);
}
fclose(ptr);
if(!is_sorted(edt, size)) {
assert(0);
}
return edt;
}
bool str_equal(char* s1, char* s2) {
// note : s1 and s2 must be valid strings (aka have \0 at the end)
if((int)(s1[0]) == 0 || (int)(s2[0]) == 0) {
return ((int)(s1[0]) == 0 && (int)(s2[0]) == 0);
} else if(s1[0] != s2[0]) {
return false;
}
return str_equal(&s1[1], &s2[1]);
}
void str_copy(char* src, int l1, char* dest) {
/* put the word src with length l1, \0 NOT included, in dest */
for(int i = 0; i <= l1; i++) {
dest[i] = src[i];
}
dest[l1] = '\0';
}
colleur* import_colleurs(char* filename, int n_colleurs, int max_available) {
/*
file has the following format :
name
mat
dates (date*)
-
name2
mat2
dates2
-
name3
...
$
*/
FILE* ptr = fopen(filename, "r");
char c = fgetc(ptr);
// {char* name; int namelen; topic mat; date* disp; int n_disp;}
colleur* res = malloc(sizeof(colleur)*n_colleurs);
char* word = malloc(sizeof(char)*30);
int wordlen = 0;
int buffer = 0;
int date_ptr = 0;
int current = 0; // 0 = name, 1 = mat, 2+ = dates
int colleur_ptr = 0;
while(c != EOF && c != '$') {
if(c == '\n') {
if(current == 0) {
word[wordlen] = '\0';
res[colleur_ptr].name = malloc(sizeof(char)*30);
str_copy(word, wordlen, res[colleur_ptr].name);
res[colleur_ptr].namelen = wordlen;
res[colleur_ptr].id = colleur_ptr;
} else if(current == 1) {
if(word[0] == 'M') { // math
res[colleur_ptr].mat = MATH;
} else if(word[0] == 'P') { // physics
res[colleur_ptr].mat = PHYSICS;
} else if(word[0] == 'E') { // english
res[colleur_ptr].mat = ENGLISH;
} else if(word[0] == 'I') { // info
res[colleur_ptr].mat = INFO;
} else {
word[wordlen] = '\0';
fatal("Wait that's illegal (%s)", word);
assert(0);
}
res[colleur_ptr].disp = malloc(sizeof(date)*max_available);
} else {
res[colleur_ptr].disp[current-2].year = buffer;
}
current++;
wordlen = 0;
buffer = 0;
date_ptr = 0;
} else if(c == '+') {
res[colleur_ptr].n_disp = current-2;
current = 0;
colleur_ptr++;
c = fgetc(ptr); // always a '\n', this to avoid some seg fault
} else {
if(current <= 1) {
word[wordlen] = c;
wordlen++;
} else {
if((int)(c) >= 48 && (int)(c) <= 57) {
buffer *= 10;
buffer += (int)(c) - 48;
} else {
if(date_ptr == 0) {
res[colleur_ptr].disp[current-2].hour = buffer;
} else if(date_ptr == 1) {
res[colleur_ptr].disp[current-2].day = buffer;
} else if(date_ptr == 2) {
res[colleur_ptr].disp[current-2].month = buffer;
} else {
fatal("Oh no (%d)", date_ptr);
assert(0);
}
buffer = 0;
date_ptr++;
}
}
}
//printf("%c", c);
c = fgetc(ptr);
}
// {char* name; int namelen; topic mat; date* disp; int n_disp;}
info("Successfully imported colleurs");
fclose(ptr);
free(word);
return res;
}
date increment_date(date d, int inc) {
int remaining = inc;
date res = d;
int delta_day = 0;
while(remaining > 0) {
res.day++;
delta_day = (res.month == 1 || res.month == 3 || res.month == 5 || res.month == 7 || res.month == 8 || res.month == 10 || res.month == 12) - 2*(res.month == 2) + (res.month == 2 && res.year%4 == 0 && res.year%100 != 0);
// sweet jesus
if(res.day > 30 + delta_day) {
res.day = 1;
if(res.month == 12) {
res.month = 1;
res.year++;
} else {
res.month++;
}
}
remaining--;
}
return res;
}
creneau* import_creneaux_oneweek(char* filename, int len_file, int n_weeks, int n_groups) {
// import creneau data from a file then copy paste it for specified amount of weeks
FILE* ptr = fopen(filename, "r");
char c = fgetc(ptr);
creneau* edt = malloc(sizeof(creneau)*len_file*n_weeks);
int i = 0;
int to_fill = 0;
int buffer = 0;
while(c != EOF && c != '$') {
if((int)(c) >= 48 && (int)(c) <= 57) {
buffer *= 10;
buffer += (int)(c) - 48;
} else {
if(to_fill == 0) {
//printf("%d\n", i);
edt[i].date.hour = buffer;
edt[i].group = 0;
edt[i].name = malloc(sizeof(char)*35);
edt[i].name[0] = 'n';
edt[i].name[1] = 'o';
edt[i].name[2] = 'n';
edt[i].name[3] = 'e';
edt[i].name[4] = '\0';
edt[i].namelen = 4;
edt[i].mat = NOTHING;
edt[i].salle.building = 'N';
edt[i].salle.id = 0;
edt[i].length = 1;
edt[i].allow_grps = malloc(sizeof(bool)*n_groups);
for(int ii = 0; ii < n_groups; ii++) {
edt[i].allow_grps[ii] = true;
}
} else if(to_fill == 1) {
edt[i].date.day = buffer;
} else if(to_fill == 2) {
edt[i].date.month = buffer;
} else if(to_fill == 3) {
edt[i].date.year = buffer;
} else {
edt[i].length++;
}
to_fill++;
buffer = 0;
if(c == '\n') {
i++;
to_fill = 0;
}
}
c = fgetc(ptr);
}
fclose(ptr);
for(int k = 1; k < n_weeks; k++) {
for(int i = 0; i < len_file; i++) {
edt[k*len_file+i].date = increment_date(edt[i].date, 7*k);
edt[k*len_file+i].group = 0;
edt[k*len_file+i].name = malloc(sizeof(char)*35);
edt[k*len_file+i].name[0] = 'n';
edt[k*len_file+i].name[1] = 'o';
edt[k*len_file+i].name[2] = 'n';
edt[k*len_file+i].name[3] = 'e';
edt[k*len_file+i].name[4] = '\0';
edt[k*len_file+i].namelen = 4;
edt[k*len_file+i].mat = NOTHING;
edt[k*len_file+i].salle.building = 'N';
edt[k*len_file+i].salle.id = 0;
edt[k*len_file+i].length = edt[i].length;
edt[k*len_file+i].allow_grps = malloc(sizeof(bool)*n_groups);
for(int ii = 0; ii < n_groups; ii++) {
edt[k*len_file+i].allow_grps[ii] = true;
}
}
}
/*for(int k = 0; k < len_file*n_weeks; k++) {
printf("%d %d %d %d %d %d\n", edt[k].date.hour, edt[k].date.day, edt[k].date.month, edt[k].date.year, edt[k].group, (int)(edt[k].mat));
}*/
if(!is_sorted(edt, n_weeks*len_file)) {
assert(0);
}
info("Imported creneaux successfully");
return edt;
}
void expand(colleur* guy, int id, int n_weeks) {
int len_1st = guy[id].n_disp;
date* new = malloc(sizeof(date)*len_1st*n_weeks);
for(int b = 0; b < len_1st; b++) {
new[b] = guy[id].disp[b];
}
for(int week = 1; week < n_weeks; week++) {
for(int i = 0; i < len_1st; i++) {
new[week*len_1st+i] = increment_date(guy[id].disp[i], 7*week);
}
}
free(guy[id].disp);
guy[id].n_disp *= n_weeks;
guy[id].disp = new;
}
colleur* import_colleurs_oneweek(char* filename, int n_colleurs, int n_weeks, int len_oneweek) {
// same as before, but each colleur only set his/her creneaux for the 1st week
FILE* ptr = fopen(filename, "r");
char c = fgetc(ptr);
// {char* name; int namelen; topic mat; date* disp; int n_disp;}
colleur* res = malloc(sizeof(colleur)*n_colleurs);
char* word = malloc(sizeof(char)*30);
int wordlen = 0;
int buffer = 0;
int date_ptr = 0;
int current = 0; // 0 = name, 1 = mat, 2+ = dates
int colleur_ptr = 0;
while(c != EOF && c != '$') {
if(c == '\n') {
if(current == 0) {
word[wordlen] = '\0';
res[colleur_ptr].name = malloc(sizeof(char)*30);
str_copy(word, wordlen, res[colleur_ptr].name);
res[colleur_ptr].namelen = wordlen;
} else if(current == 1) {
if(word[0] == 'M') { // math
res[colleur_ptr].mat = MATH;
//printf("M");
} else if(word[0] == 'P') { // physics
res[colleur_ptr].mat = PHYSICS;
//printf("P");
} else if(word[0] == 'E') { // english
res[colleur_ptr].mat = ENGLISH;
//printf("E");
} else if(word[0] == 'I') { // info
res[colleur_ptr].mat = INFO;
} else {
word[wordlen] = '\0';
fatal("Wait that's illegal (%s)", word);
assert(0);
}
res[colleur_ptr].disp = malloc(sizeof(date)*len_oneweek);
res[colleur_ptr].id = colleur_ptr;
} else {
res[colleur_ptr].disp[current-2].year = buffer;
}
current++;
wordlen = 0;
buffer = 0;
date_ptr = 0;
} else if(c == '+') {
res[colleur_ptr].n_disp = current-2;
current = 0;
colleur_ptr++;
c = fgetc(ptr); // always a '\n', this to avoid some seg fault
} else {
if(current <= 1) {
word[wordlen] = c;
wordlen++;
} else {
if((int)(c) >= 48 && (int)(c) <= 57) {
buffer *= 10;
buffer += (int)(c) - 48;
} else {
if(date_ptr == 0) {
res[colleur_ptr].disp[current-2].hour = buffer;
} else if(date_ptr == 1) {
res[colleur_ptr].disp[current-2].day = buffer;
} else if(date_ptr == 2) {
res[colleur_ptr].disp[current-2].month = buffer;
} else {
fatal("Oh no (%d)", date_ptr);
assert(0);
}
buffer = 0;
date_ptr++;
}
}
}
//printf("%c", c);
c = fgetc(ptr);
}
// {char* name; int namelen; topic mat; date* disp; int n_disp;}
for(int c = 0; c < n_colleurs; c++) {
expand(res, c, n_weeks);
}
fclose(ptr);
free(word);
info("Imported colleurs with no problems");
return res;
}
int str_to_int(char* s) {
char c = 'e';
int i = 0;
int buffer = 0;
while(c != '\0') {
c = s[i];
buffer *= 10;
if((int)(c) >= 48 && (int)(c) <= 57) {
buffer += (int)(c)-48;
}
i++;
}
return buffer/10;
}
bool equal_d(date d1, date d2) {
return (d1.hour == d2.hour && d2.day == d1.day && d1.month == d2.month && d1.year == d2.year);
}
int locate_date(creneau* edt, int len_edt, date d) {
int i = 0;
while(i < len_edt && !equal_d(edt[i].date, d)) {
i++;
}
if(i == len_edt) {
return -1;
}
return i;
}
void import_tds(creneau* edt, int len_edt, int len_oneweek, char* filename) {
FILE* ptr = fopen(filename, "r");
char c = fgetc(ptr);
int edtptr = 0;
int current = 0;
int place = 0;
char method;
int buffer = 0;
date d;
while(c != EOF && c != '$') {
//printf("%c", c);
if(c == '+') {
current = 0;
place = 0;
buffer = 0;
c = fgetc(ptr); // always a \n
} else if(c == '\n' && current != 0) {
if(current == 1) {
edtptr = locate_date(edt, len_edt, d);
} else {
if(method == 'A') {
int k = 0;
int os = 1;
while(edtptr + k*len_oneweek >= 0 && edtptr + k*len_oneweek < len_edt) {
//info("[%d, %d]", buffer, edtptr + k*len_oneweek);
//usleep(1000000);
edt[edtptr + k*len_oneweek].allow_grps[buffer-1] = false;
while(equal_d(edt[edtptr + k*len_oneweek].date, edt[edtptr + k*len_oneweek + os].date)) {
//info("[%d, %d]", buffer, edtptr + k*len_oneweek + os);
edt[edtptr + k*len_oneweek + os].allow_grps[buffer-1] = false;
os++;
}
k++;
os = 1;
}
} else {
fatal("Unknown method %d. Check if the method used is valid, or ask a dev to fix it ", method);
exit(1);
}
}
current++;
buffer = 0;
} else if((c == '\n' && current == 0) || c == ' ') {
if(place == 0) {
d.hour = buffer;
} else if(place == 1) {
d.day = buffer;
} else if(place == 2) {
d.month = buffer;
} else {
d.year = buffer;
current = 1;
}
place++;
buffer = 0;
} else if((int)(c) >= 48 && (int)(c) <= 57) {
buffer *= 10;
buffer += (int)(c) - 48;
} else if(current == 1) {
method = c;
}
c = fgetc(ptr);
}
fclose(ptr);
info("Imported special creneaux successfully");
}