def run(self, specification, coefficients, agent_set,
            agents_index=None, *args, **kargs):

        if agent_set is None:
            logger.log_status('No developments need to be allocated')
            return

        if agents_index is None:
            agents_index = arange(agent_set.size())
        if not isinstance(agents_index, ndarray):
            try:
                agents_index = array(agents_index)
            except:
                raise TypeError, "Argument agents_index is of wrong type (numpy array or list allowed.)"
        id_name = self.choice_set.get_id_name()[0]
        unplaced = arange(agents_index.size)
        for run in range(self.max_runs):
            choices = LocationChoiceModel.run(self, specification, coefficients, agent_set,
                                              agents_index[unplaced], *args, **kargs)
            if run == 0:
                all_choices=choices
            else:
                all_choices[unplaced]=choices

            from opus_core.sampling_toolbox import find_duplicates
            unplaced = where(find_duplicates(all_choices))[0]
            if unplaced.size <= 0:
                break
            agent_set.set_values_of_one_attribute(id_name, -1, agents_index[unplaced])
        return all_choices

        LocationChoiceModel.run(self, *args, **kargs)
 def test_sample_noreplace(self):
     start_time = time.time()
     sample = sample_noreplace(self.all, self.size, return_index=True)
     logger.log_status("sample_noreplace %s from %s items array in " % (self.size,self.n) + str(time.time() - start_time) + " sec")
     self.assertEqual(sample.size, self.size, msg ="sample size not equal to size parameter")
     assert isinstance(sample, ndarray), "sample is not of type ndarray"
     assert 0 <= sample.min() <= self.n-1, "sampled elements not in between min and max of source array"
     assert 0 <= sample.max() <= self.n-1, "sampled elements not in between min and max of source array"
     assert not sometrue(find_duplicates(sample)), "there are duplicates in samples"
 def test_prob2dsample(self):
     start_time = time.time()
     sample = prob2dsample(self.all, self.sample_size, self.prob, return_index=True)
     logger.log_status("prob2dsample (%s, %s) items array in " % self.sample_size + str(time.time() - start_time) + " sec")
     self.assertEqual(sample.shape, self.sample_size, msg ="sample size not equal to sample size parameter")
     assert isinstance(sample, ndarray), "sample is not of type ndarray"
     assert 0 <= sample.min() <= self.n-1, "sampled elements not in between min and max of source array"
     assert 0 <= sample.max() <= self.n-1, "sampled elements not in between min and max of source array"
     assert all(not_equal(self.prob[sample], 0.0)), "elements with zero weight in the sample"
     for i in range(sample.shape[0]):
         assert not sometrue(find_duplicates(sample[i,:])), "there are duplicates in samples at row %s" % i
    def run(self,
            specification,
            coefficients,
            agent_set,
            agents_index=None,
            *args,
            **kargs):

        if agent_set is None:
            logger.log_status('No developments need to be allocated')
            return

        if agents_index is None:
            agents_index = arange(agent_set.size())
        if not isinstance(agents_index, ndarray):
            try:
                agents_index = array(agents_index)
            except:
                raise TypeError, "Argument agents_index is of wrong type (numpy array or list allowed.)"
        id_name = self.choice_set.get_id_name()[0]
        unplaced = arange(agents_index.size)
        for run in range(self.max_runs):
            choices = LocationChoiceModel.run(self, specification,
                                              coefficients, agent_set,
                                              agents_index[unplaced], *args,
                                              **kargs)
            if run == 0:
                all_choices = choices
            else:
                all_choices[unplaced] = choices

            from opus_core.sampling_toolbox import find_duplicates
            unplaced = where(find_duplicates(all_choices))[0]
            if unplaced.size <= 0:
                break
            agent_set.set_values_of_one_attribute(id_name, -1,
                                                  agents_index[unplaced])
        return all_choices

        LocationChoiceModel.run(self, *args, **kargs)