How to use the ciw.auxiliary.random_choice function in Ciw

To help you get started, we’ve selected a few Ciw examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github CiwPython / Ciw / ciw / node.py View on Github external
def next_node(self, ind):
        """
        Finds the next node according the routing method:
          - if not process-based then sample from transtition matrix
          - if process-based then take the next value from the predefined route,
            removing the current node from the route
        """
        if not self.simulation.network.process_based:
            customer_class = ind.customer_class
            return random_choice(self.simulation.nodes[1:],
                self.transition_row[customer_class] + [1.0 - sum(
                self.transition_row[customer_class])])
        if ind.route == [] or ind.route[0] != self.id_number:
            raise ValueError('Individual process route sent to wrong node')
        ind.route.pop(0)
        if len(ind.route) == 0:
            next_node_number = -1
        else:
            next_node_number = ind.route[0]
        return self.simulation.nodes[next_node_number]
github CiwPython / Ciw / ciw / node.py View on Github external
def find_next_individual(self):
        """
        Finds the next individual that should now finish service.
        """
        next_individual_indices = [i for i, ind in enumerate(
            self.all_individuals) if ind.service_end_date == self.next_event_date]
        if len(next_individual_indices) > 1:
            next_individual_index = random_choice(next_individual_indices)
        else:
            next_individual_index = next_individual_indices[0]
        return self.all_individuals[next_individual_index], next_individual_index
github CiwPython / Ciw / ciw / node.py View on Github external
def change_customer_class(self,individual):
        """
        Takes individual and changes customer class
        according to a probability distribution.
        """
        if self.class_change:
            individual.previous_class = individual.customer_class
            individual.customer_class = random_choice(
                range(self.simulation.network.number_of_classes),
                self.class_change[individual.previous_class])
            individual.prev_priority_class = individual.priority_class
            individual.priority_class = self.simulation.network.priority_class_mapping[individual.customer_class]