/** * distribution of choices for each user * take care about max_execution_time and memory_limit */ public function distrubute_choices() { require_capability('mod/ratingallocate:start_distribution', $this->context); // Set algorithm status to running $this->origdbrecord->algorithmstatus = \mod_ratingallocate\algorithm_status::running; $this->origdbrecord->algorithmstarttime = time(); $this->db->update_record(this_db\ratingallocate::TABLE, $this->origdbrecord); $distributor = new solver_edmonds_karp(); // $distributor = new solver_ford_fulkerson(); $timestart = microtime(true); $distributor->distribute_users($this); $time_needed = microtime(true) - $timestart; // echo memory_get_peak_usage(); // Set algorithm status to finished $this->origdbrecord->algorithmstatus = \mod_ratingallocate\algorithm_status::finished; $this->db->update_record(this_db\ratingallocate::TABLE, $this->origdbrecord); return $time_needed; }
/** * Test id conversions from user+choicids to graphids */ public function test_setupids() { $ratings = array(); $ratings[1] = new stdClass(); $ratings[1]->userid = 3; $ratings[1]->choiceid = 1; $ratings[1]->rating = 5; $ratings[2] = new stdClass(); $ratings[2]->userid = 3; $ratings[2]->choiceid = 2; $ratings[2]->rating = 3; $ratings[3] = new stdClass(); $ratings[3]->userid = 2; $ratings[3]->choiceid = 1; $ratings[3]->rating = 5; $ratings[4] = new stdClass(); $ratings[4]->userid = 2; $ratings[4]->choiceid = 2; $ratings[4]->rating = 2; $usercount = 2; list($fromuserid, $touserid, $fromchoiceid, $tochoiceid) = solver_edmonds_karp::setup_id_conversions($usercount, $ratings); $this->assertEquals(array(3 => 1, 2 => 2), $fromuserid); $this->assertEquals(array(1 => 3, 2 => 2), $touserid); $this->assertEquals(array(1 => 3, 2 => 4), $fromchoiceid); $this->assertEquals(array(3 => 1, 4 => 2), $tochoiceid); }