count($colors)) error_system('te weinig kleuren'); $moment_to_color = array(); $color_to_moment = array(); foreach ($moments as $id => $moment) { $moment_to_color[$id] = count($color_to_moment); $color_to_moment[] = $id; } $max_colors = count($color_to_moment); $toetstranslate = get_toetsnames_index($db, $period_id); foreach ($toetsen as $toets => $info) { $toetsen[$toets]['pta_id'] = $toetstranslate[$toets]; } $rooster2 = get_rooster($db, $period_id); $collections = array(); make_collections($collections, $toetsen); function check_consistent() { global $toetsen, $collections, $max_colors, $rooster2, $moment_to_color; set_colors_from_rooster2($toetsen, $rooster2, $moment_to_color); //print_r($rooster); foreach ($collections as $id => $collection) { usort($collections[$id]['list'], function ($a, $b) use (&$toetsen) { return count($toetsen[$a]['neighbors']) < count($toetsen[$b]['neighbors']); }); $collections[$id]['used_colors'] = array(); $collections[$id]['to_research'] = array(); // elke toets krijgt een 'idx', deze geeft aan in welke volgorde // de toetsen een kleur krijgen; toetsen met idx = -1 hebben al een kleur // toetsen met idx = PHP_INT_MAX hoeven niet te worden bezocht, omdat ze zowiezo // inkleurbaar zijn (aantal verbindingen < max colors) $collections[$id]['idx'] = array(); $collections[$id]['no_idx'] = 0; foreach ($collections[$id]['list'] as $name) { $toets = $toetsen[$name]; //print_r($toets); $color = $toets['color']; if ($color === NULL) { if (count($toets['neighbors']) >= $max_colors) { $collections[$id]['to_research'][] = $name; $collections[$id]['idx'][$name] = $collections[$id]['no_idx']++; } else $collections[$id]['idx'][$name] = PHP_INT_MAX; continue; } $collections[$id]['idx'][$name] = -1; $collections[$id]['used_colors'][$color] = true; if (!check_neighbors($toetsen, $toets['neighbors'], $color)) { return false; } } foreach ($collections[$id]['to_research'] as $name) { uksort($toetsen[$name]['neighbors'], function ($a, $b) use ($collections, $id) { //print_r($collections); return $collections[$id]['idx'][$a] > $collections[$id]['idx'][$b]; }); } } return true; } header('Content-type: text/plain; charset=UTF-8'); //header('Content-type: application/json; charset=UTF-8'); $gevonden = NULL; foreach ($toetsen as $id => $toets) { if ($toets['pta_id'] == $_GET['pta_id']) { $gevonden = $id; break; } } // een niet gevonden toets, kan niet gevonden zijn omdat // er opeens geen inschrijvingen meer zijn, deze toets // mag teruggeplaatst worden naar het 'te roosteren' vlak if (!$gevonden) { $result = array( 'ok' => array(0), 'nak' => array() ); for ($i = 0; $i < $max_colors; $i++) { $result['nak'][] = $color_to_moment[$i]; } echo(json_encode($result)); exit; } $result = array('ok' => array(0), 'nak' => array()); $graph_id = $toetsen[$gevonden]['graph']; set_colors_from_rooster2($toetsen, $rooster2, $moment_to_color); $bad_colors = get_bad_colors2($toetsen, $gevonden, NULL, $max_colors); /* echo("gevonden: $gevonden $graph_id\n"); print_r($collections[$graph_id]); echo("max_colors=$max_colors\n"); print_r($bad_colors); */ $firstrun = 1; foreach ($bad_colors as $color => $used) { if ($used) { $result['nak'][] = $color_to_moment[$color]; continue; } if (!$firstrun) { set_colors_from_rooster2($toetsen, $rooster2, $moment_to_color); } $toetsen[$gevonden]['color'] = $color; if ($firstrun) { if (!check_consistent()) { $result = array( 'consistent' => 'false', 'ok' => array(0), 'nak' => array() ); for ($i = 0; $i < $max_colors; $i++) { $result['nak'][] = $color_to_moment[$i]; } echo(json_encode($result)); exit; } $firstrun = 0; } if (research($toetsen, $collections[$graph_id]['to_research'], $collections[$graph_id], $max_colors)) { $result['ok'][] = $color_to_moment[$color]; } else { $result['nak'][] = $color_to_moment[$color]; } } echo(json_encode($result)); ?>