Ejemplo n.º 1
0
    def three(self):
        """
        """
        if self.id % 2 == 0:
            offer = self.offer
            if offer.status == 'rejected':
                test = self.money - self['money']
                assert is_zero(test), test
                self.tests['rejected'] = True
            elif offer.status == 'accepted':
                if offer.final_quantity == offer.quantity:
                    assert self.money - offer.quantity * \
                        offer.price == self['money']

                    assert self['cookies'] == offer.quantity
                    self.tests['accepted'] = True
                else:
                    test = (self.money - offer.final_quantity *
                            offer.price) - self['money']
                    assert is_zero(test), test
                    test = self['cookies'] - offer.final_quantity
                    assert is_zero(test), test
                    self.tests['partial'] = True
            else:
                SystemExit('Error in buy')
Ejemplo n.º 2
0
    def three(self):
        """
        """
        if self.id % 2 == 0:
            offer = self.offer
            if offer.status == 'rejected':
                test = self.money - self.possession('money')
                assert is_zero(test), test
                self.tests['rejected'] = True
            elif offer.status == 'accepted':
                if offer.final_quantity == offer.quantity:
                    assert self.money - offer.quantity * \
                        offer.price == self.possession('money')

                    assert self.possession('cookies') == offer.quantity
                    self.tests['accepted'] = True
                else:
                    test = (self.money - offer.final_quantity *
                            offer.price) - self.possession('money')
                    assert is_zero(test), test
                    test = self.possession('cookies') - offer.final_quantity
                    assert is_zero(test), test
                    self.tests['partial'] = True
            else:
                SystemExit('Error in buy')
Ejemplo n.º 3
0
    def consumption(self):
        if self.id == 0:
            self.create('a', 10)
            self.create('b', 10)
            self.create('c', 10)
            utility = self.consume(self.utility_function, {'a': 5, 'b': 3, 'c': 1})
            assert utility == max(5 ** 0.2, 3 ** 0.5 * 1 ** 0.3), utility
            assert self['a'] == 5
            assert self['b'] == 9.7
            assert self['c'] == 10
            self.destroy('a')
            self.destroy('b')
            self.destroy('c')

        elif self.id == 1:
            self.create('a', 10)
            self.create('b', 10)
            self.create('c', 10)
            utility = self.consume(self.utility_function, {'a': 5, 'b': 3, 'c': 1})
            assert utility == 5 ** 0.2 * 3 ** 0.5 * 1 ** 0.3, utility
            assert self['a'] == 5
            assert self['b'] == 7
            assert self['c'] == 9
            self.consume(self.utility_function, ['a', 'b', 'c'])
            assert self['a'] == 0
            assert self['b'] == 0
            assert self['c'] == 0

            pu = self.utility_function(**{'a': 5, 'b': 300, 'c': 10})
            assert pu == 5 ** 0.2 * 300 ** 0.5 * 10 ** 0.3

        elif self.id == 2:
            self.create('a', 10)
            self.create('b', 10)
            self.create('c', 10)
            utility = self.consume(self.utility_function, ['a', 'b', 'c'])
            assert is_zero(utility - max(10 ** 0.2, 10 ** 0.5 * 10 ** 0.3)
                           ), (utility, max(10 ** 0.2, 10 ** 0.5 * 10 ** 0.3))
            assert self['a'] == 0
            assert self['b'] == 9
            assert self['c'] == 10
            self.destroy('a')
            self.destroy('b')
            self.destroy('c')

        elif self.id == 3:
            self.create('a', 10)
            self.create('b', 10)
            self.create('c', 10)
            utility = self.consume(self.utility_function, ['a', 'b', 'c'])
            assert is_zero(utility - 10 ** 0.2 * 10 ** 0.5 * 10 **
                           0.3), (utility, 10 ** 0.2 * 10 ** 0.5 * 10 ** 0.3)
            assert self['a'] == 0
            assert self['b'] == 0
            assert self['c'] == 0

            pu = self.utility_function(**{'a': 5, 'b': 300, 'c': 10})
            assert pu == 5 ** 0.2 * 300 ** 0.5 * 10 ** 0.3
Ejemplo n.º 4
0
    def consumption(self):
        if self.id == 0:
            self.create('a', 10)
            self.create('b', 10)
            self.create('c', 10)
            utility = self.consume(self.utility_function, {'a': 5, 'b': 3, 'c': 1})
            assert utility == max(5 ** 0.2, 3 ** 0.5 * 1 ** 0.3), utility
            assert self['a'] == 5
            assert self['b'] == 9.7
            assert self['c'] == 10
            self.destroy('a')
            self.destroy('b')
            self.destroy('c')

        elif self.id == 1:
            self.create('a', 10)
            self.create('b', 10)
            self.create('c', 10)
            utility = self.consume(self.utility_function, {'a': 5, 'b': 3, 'c': 1})
            assert utility == 5 ** 0.2 * 3 ** 0.5 * 1 ** 0.3, utility
            assert self['a'] == 5
            assert self['b'] == 7
            assert self['c'] == 9
            self.consume(self.utility_function, ['a', 'b', 'c'])
            assert self['a'] == 0
            assert self['b'] == 0
            assert self['c'] == 0

            pu = self.utility_function(**{'a': 5, 'b': 300, 'c': 10})
            assert pu == 5 ** 0.2 * 300 ** 0.5 * 10 ** 0.3

        elif self.id == 2:
            self.create('a', 10)
            self.create('b', 10)
            self.create('c', 10)
            utility = self.consume(self.utility_function, ['a', 'b', 'c'])
            assert is_zero(utility - max(10 ** 0.2, 10 ** 0.5 * 10 ** 0.3)
                           ), (utility, max(10 ** 0.2, 10 ** 0.5 * 10 ** 0.3))
            assert self['a'] == 0
            assert self['b'] == 9
            assert self['c'] == 10
            self.destroy('a')
            self.destroy('b')
            self.destroy('c')

        elif self.id == 3:
            self.create('a', 10)
            self.create('b', 10)
            self.create('c', 10)
            utility = self.consume(self.utility_function, ['a', 'b', 'c'])
            assert is_zero(utility - 10 ** 0.2 * 10 ** 0.5 * 10 **
                           0.3), (utility, 10 ** 0.2 * 10 ** 0.5 * 10 ** 0.3)
            assert self['a'] == 0
            assert self['b'] == 0
            assert self['c'] == 0

            pu = self.utility_function(**{'a': 5, 'b': 300, 'c': 10})
            assert pu == 5 ** 0.2 * 300 ** 0.5 * 10 ** 0.3
Ejemplo n.º 5
0
    def compute_triangular_form(self):
        """
        >>> s = LinearSystem(Plane(Vector(1, 1, 1), 1),
        ...                  Plane(Vector(0, 1, 1), 2))
        >>> t = s.compute_triangular_form()
        >>> t[0], t[1]
        (Plane(Vector(1, 1, 1), 1), Plane(Vector(0, 1, 1), 2))
        >>> s = LinearSystem(Plane(Vector(1, 1, 1), 1), 
        ...                  Plane(Vector(1, 1, 1), 2))
        >>> t = s.compute_triangular_form()
        >>> t[0], t[1]
        (Plane(Vector(1, 1, 1), 1), Plane(Vector(0, 0, 0), 1))
        >>> s = LinearSystem(Plane(Vector(1, 1, 1), 1),
        ...                  Plane(Vector(0, 1, 0), 2),
        ...                  Plane(Vector(1, 1, -1), 3),
        ...                  Plane(Vector(1, 0, -2), 2))
        >>> t = s.compute_triangular_form()
        >>> t[0], t[1]
        (Plane(Vector(1, 1, 1), 1), Plane(Vector(0, 1, 0), 2))
        >>> t[2], t[3]
        (Plane(Vector(0, 0, -2), 2), Plane(Vector(0, 0, 0), 0))

        >>> s = LinearSystem(Plane(Vector(0, 1, 1), 1),
        ...                  Plane(Vector(1, -1, 1), 2),
        ...                  Plane(Vector(1, 2, -5), 3))
        >>> t = s.compute_triangular_form()
        >>> t[0]
        Plane(Vector(1, -1, 1), 2)
        >>> t[1]
        Plane(Vector(0, 1, 1), 1)
        >>> t[2]
        Plane(Vector(0, 0, -9), -2)
        """
        system = deepcopy(self)

        equations = len(system)
        cycles = min([system.dimension, equations])

        for i in range(cycles):
            if is_zero(system[i].normal_vector[i]):
                for j in range(i + 1, equations):
                    if not is_zero(system[j].normal_vector[i]):
                        system.swap_rows(i, j)
                        break
                else:
                    continue

            for j in range(i + 1, equations):
                k = -system[j].normal_vector[i] / system[i].normal_vector[i]
                system.add_multiple_times_row_to_row(k, i, j)

        return system
Ejemplo n.º 6
0
 def two(self):
     """ Acts only if he is agent 1: recieves quotes and accepts;
     rejects; partially accepts and leaves quotes unanswerd.
     """
     if self.id == 1:
         self.create('cookies', random.uniform(0, 10000))
         cookies = self['cookies']
         if random.randint(0, 1) == 0:
             quotes = self.get_quotes('cookies')
         else:
             quotes = self.get_quotes_all()
             quotes = quotes['cookies']
         assert quotes
         for quote in quotes:
             if random.randint(0, 1) == 0:
                 self.tests['not_answered'] = True
                 continue
             if self['cookies'] >= quote['quantity']:
                 self.accept_quote(quote)
                 self.final_money = quote['price'] * quote['quantity']
                 assert self['cookies'] == cookies - quote['quantity']
                 self.tests['accepted'] = True
             else:
                 self.accept_quote_partial(quote, self['cookies'])
                 assert is_zero(self['cookies'])
                 self.final_money = cookies * quote['price']
                 self.tests['partial'] = True
Ejemplo n.º 7
0
 def two(self):
     """ Acts only if he is agent 1: recieves quotes and accepts;
     rejects; partially accepts and leaves quotes unanswerd.
     """
     if self.id == 1:
         self.create('cookies', random.uniform(0, 10000))
         cookies = self['cookies']
         if random.randint(0, 1) == 0:
             quotes = self.get_quotes('cookies')
         else:
             quotes = self.get_quotes_all()
             quotes = quotes['cookies']
         assert quotes
         for quote in quotes:
             if random.randint(0, 1) == 0:
                 self.tests['not_answered'] = True
                 continue
             if self['cookies'] >= quote['quantity']:
                 self.accept_quote(quote)
                 self.final_money = quote['price'] * quote['quantity']
                 assert self['cookies'] == cookies - quote['quantity']
                 self.tests['accepted'] = True
             else:
                 self.accept_quote_partial(
                     quote, self['cookies'])
                 assert is_zero(self['cookies'])
                 self.final_money = cookies * quote['price']
                 self.tests['partial'] = True
Ejemplo n.º 8
0
 def two(self):
     """ Acts only if he is agent 1: recieves offers and accepts;
     rejects; partially accepts and leaves offers unanswerd.
     """
     if self.id % 2 == 1:
         self.create('cookies', random.uniform(0, 10000))
         cookies = self.possession('cookies')
         oo = self.get_offers('cookies')
         assert oo
         for offer in oo:
             if random.randint(0, 10) == 0:
                 self.tests['not_answered'] = True
                 continue
             elif random.randint(0, 10) == 0:
                 self.reject(offer)
                 assert self.possession('money') == 0
                 assert self.possession('cookies') == cookies
                 self.tests['rejected'] = True
                 break  # tests the automatic clean-up of polled offers
             try:
                 self.accept(offer)
                 assert self.possession(
                     'money') == offer.price * offer.quantity
                 assert self.possession(
                     'cookies') == cookies - offer.quantity
                 self.tests['accepted'] = True
             except NotEnoughGoods:
                 self.accept(offer, self.possession('cookies'))
                 assert is_zero(self.possession('cookies'))
                 assert self.possession('money') == cookies * offer.price
                 self.tests['partial'] = True
Ejemplo n.º 9
0
 def two(self):
     """ Acts only if he is agent 1: recieves offers and accepts;
     rejects; partially accepts and leaves offers unanswerd.
     """
     if self.id % 2 == 1:
         self.create('cookies', random.uniform(0, 10000))
         cookies = self.possession('cookies')
         oo = self.get_offers('cookies')
         assert oo
         for offer in oo:
             if random.randint(0, 10) == 0:
                 self.tests['not_answered'] = True
                 continue
             elif random.randint(0, 10) == 0:
                 self.reject(offer)
                 assert self.possession('money') == 0
                 assert self.possession('cookies') == cookies
                 self.tests['rejected'] = True
                 break  # tests the automatic clean-up of polled offers
             try:
                 self.accept(offer)
                 assert self.possession('money') == offer.price * offer.quantity
                 assert self.possession('cookies') == cookies - offer.quantity
                 self.tests['accepted'] = True
             except NotEnoughGoods:
                 self.accept(offer, self.possession('cookies'))
                 assert is_zero(self.possession('cookies'))
                 assert self.possession('money') == cookies * offer.price
                 self.tests['partial'] = True
Ejemplo n.º 10
0
Archivo: sell.py Proyecto: sunrash/abce
 def three(self):
     if self.id % 2 == 0:
         offer = self.offer
         if offer.status == 'rejected':
             assert is_zero(self.cookies - self['cookies'])
             self.tests['rejected'] = True
         elif offer.status == 'accepted':
             if offer.final_quantity == offer.quantity:
                 assert self.cookies - \
                     offer.quantity == self['cookies']
                 assert self['money'] == offer.quantity * offer.price
                 self.tests['accepted'] = True
             else:
                 test = (self.cookies - offer.final_quantity) - \
                     self['cookies']
                 assert is_zero(test), test
                 test = self['money'] - \
                     offer.final_quantity * offer.price
                 assert is_zero(test), test
                 self.tests['partial'] = True
                 self.tests['full_partial'] = True
         else:
             SystemExit('Error in sell')
Ejemplo n.º 11
0
    def solve(self):
        system = self.compute_rref()
        answer = [0] * system.dimension
        useful_equations = []
        for i, plane in enumerate(system):
            j = first_nonzero_index(plane.normal_vector)
            if j is None:
                if not is_zero(plane.constant_term):
                    return None
                continue
            useful_equations.append(plane)
            answer[j] = plane.constant_term

        if len(useful_equations) < self.dimension:
            return self.build_parametrization(useful_equations)

        return Vector(*answer)
Ejemplo n.º 12
0
    def __eq__(self, other: 'Line') -> bool:
        """
        >>> Line(Vector(2, 3), 5) == Line(Vector(4, 6), 10)
        True
        >>> Line(Vector(2, 3), 5) == Line(Vector(4, 5), 10)
        False
        """
        if not self.normal_vector:
            if other.normal_vector:
                return False
            else:
                diff = self.constant_term - other.constant_term
                return is_zero(diff)
        elif not other.normal_vector:
            return False

        if not self.is_parallel(other):
            return False

        middle_vector = self.base_point - other.base_point

        return self.normal_vector.is_orthogonal(middle_vector)
Ejemplo n.º 13
0
    def production(self):
        self.create('a', 2)
        self.create('b', 2)
        self.produce(self.pf, {'a': 1, 'b': 2})

        assert self['a'] == 1, self['a']
        assert self['b'] == 1.8, self['b']
        assert is_zero(self['consumption_good'] - 1. ** 0.5 * 2), \
            self['consumption_good']
        self.destroy('a')
        self.destroy('b')
        self.destroy('consumption_good')

        result = self.pf(**{'a': 10, 'b': 10})
        assert result['consumption_good'] == max(10**2, 10**0.5 * 10)
        assert result['a'] == 0, result['a']
        assert result['b'] == 9, result['b']

        self.create('a', 2)
        self.create('b', 2)
        self.produce(self.cd, {'a': 1, 'b': 2})

        assert self['a'] == 1, self['a']
        assert self['b'] == 0, self['b']
        assert self['consumption_good'] == 5 * \
            1 ** 2 * 2 ** 1, self['consumption_good']
        self.destroy('a')
        self.destroy('b')
        self.destroy('consumption_good')

        self.create('a', 2)
        self.create('b', 2)
        self.produce(self.leontief, {'a': 1, 'b': 2})

        assert self['a'] == 1, self['a']
        assert self['b'] == 0, self['b']
        assert self['consumption_good'] == min(1 * 3,
                                               2 * 1), self['consumption_good']
        self.destroy('a')
        self.destroy('consumption_good')

        self.create('a', 10)
        self.create('b', 10)
        self.create('c', 10)
        self.produce(self.many_goods_pf, {'a': 1, 'b': 2, 'c': 5})

        assert self['a'] == 9, self['a']
        assert self['b'] == 9.8, self['b']
        assert self['c'] == 10, self['c']
        assert self['soft_rubber'] == 1 ** 0.25 * \
            2 ** 0.5 * 5 ** 0.25, self['soft_rubber']
        assert self['hard_rubber'] == 1 ** 0.1 * \
            2 ** 0.2 * 5 ** 0.01, self['hard_rubber']
        assert self['waste'] == 2 / 2, self['waste']
        self.destroy('a')
        self.destroy('b')
        self.destroy('c')
        self.destroy('soft_rubber')
        self.destroy('hard_rubber')
        self.destroy('waste')

        self.create('a', 2)
        self.create('b', 2)
        self.create('c', 4)
        self.produce(self.ces, {'a': 1, 'b': 2, 'c': 4})

        assert self['a'] == 1, self['a']
        assert self['b'] == 0, self['b']
        assert self['c'] == 0, self['c']
        expected = (0.25 * 1**0.5 + 0.25 * 2**0.5 + 0.5 * 4**0.5)**(1 / 0.5)
        assert self['consumption_good'] == expected, (self['consumption_good'],
                                                      expected)
        self.destroy('a', 1)
        self.destroy('consumption_good', expected)

        self.create('a', 2)
        self.create('b', 2)
        self.create('c', 2)
        self.create('d', 2)
        self.create('e', 2)
        self.produce(self.ces_flexible, {
            'a': 1,
            'b': 2,
            'c': 2,
            'd': 2,
            'e': 2
        })

        assert self['a'] == 1, self['a']
        assert self['b'] == 0, self['b']
        assert self['c'] == 0, self['c']
        assert self['d'] == 0, self['d']
        assert self['e'] == 0, self['e']
        expected = (2 * (0.2 * 1**0.5 + 0.2 * 2**0.5 + 0.2 * 2**0.5 +
                         0.2 * 2**0.5 + 0.2 * 2**0.5)**(1 / 0.5))
        assert is_zero(self['consumption_good'] -
                       expected), (self['consumption_good'], expected)
        self.destroy('a', 1)
        self.destroy('consumption_good', expected)
Ejemplo n.º 14
0
    def production(self):
        self.create('a', 2)
        self.create('b', 2)
        self.produce(self.pf, {'a': 1, 'b': 2})

        assert self.possession('a') == 1, self.possession('a')
        assert self.possession('b') == 1.8, self.possession('b')
        assert is_zero(self.possession('consumption_good') - 1. ** 0.5 * 2), \
            self.possession('consumption_good')
        self.destroy('a')
        self.destroy('b')
        self.destroy('consumption_good')

        output = self.predict_produce_output(self.pf, {'a': 10, 'b': 10})
        assert output['consumption_good'] == max(10 ** 2, 10 ** 0.5 * 10)

        input = self.predict_produce_input(self.pf, {'a': 10, 'b': 10})
        assert input['a'] == 10, input['a']
        assert input['b'] == 1, input['b']

        nv = self.net_value(
            output, input, {'consumption_good': 10, 'a': 1, 'b': 2})
        assert nv == 100 * 10 - (10 * 1 + 1 * 2), nv

        self.create('a', 2)
        self.create('b', 2)
        self.produce(self.cd, {'a': 1, 'b': 2})

        assert self.possession('a') == 1, self.possession('a')
        assert self.possession('b') == 0, self.possession('b')
        assert self.possession('consumption_good') == 5 * \
            1 ** 2 * 2 ** 1, self.possession('consumption_good')
        self.destroy('a')
        self.destroy('b')
        self.destroy('consumption_good')

        self.create('a', 2)
        self.create('b', 2)
        self.produce(self.leontief, {'a': 1, 'b': 2})

        assert self.possession('a') == 1, self.possession('a')
        assert self.possession('b') == 0, self.possession('b')
        assert self.possession('consumption_good') == min(
            1 * 3, 2 * 1), self.possession('consumption_good')
        self.destroy('a')
        self.destroy('consumption_good')

        self.create('a', 10)
        self.create('b', 10)
        self.create('c', 10)
        self.produce(self.many_goods_pf, {'a': 1, 'b': 2, 'c': 5})

        assert self.possession('a') == 9, self.possession('a')
        assert self.possession('b') == 9.8, self.possession('b')
        assert self.possession('c') == 10, self.possession('c')
        assert self.possession('soft_rubber') == 1 ** 0.25 * \
            2 ** 0.5 * 5 ** 0.25, self.possession('soft_rubber')
        assert self.possession('hard_rubber') == 1 ** 0.1 * \
            2 ** 0.2 * 5 ** 0.01, self.possession('hard_rubber')
        assert self.possession('waste') == 2 / 2, self.possession('waste')
        self.destroy('a')
        self.destroy('b')
        self.destroy('c')
        self.destroy('soft_rubber')
        self.destroy('hard_rubber')
        self.destroy('waste')

        input_goods = {'wheels': 4, 'chassi': 1}
        price_vector = {'wheels': 10, 'chassi': 100, 'car': 1000}
        nv = self.predict_net_value(self.car, input_goods, price_vector)
        assert nv == 860

        self.create('a', 2)
        self.create('b', 2)
        self.create('c', 4)
        self.produce(self.ces, {'a': 1, 'b': 2, 'c': 4})

        assert self.possession('a') == 1, self.possession('a')
        assert self.possession('b') == 0, self.possession('b')
        assert self.possession('c') == 0, self.possession('c')
        expected = (0.25 * 1 ** 0.5 + 0.25 * 2 **
                    0.5 + 0.5 * 4 ** 0.5) ** (1 / 0.5)
        assert self.possession('consumption_good') == expected, (
            self.possession('consumption_good'), expected)
        self.destroy('a', 1)
        self.destroy('consumption_good', expected)

        self.create('a', 2)
        self.create('b', 2)
        self.create('c', 2)
        self.create('d', 2)
        self.create('e', 2)
        self.produce(self.ces_flexible, {
                     'a': 1, 'b': 2, 'c': 2, 'd': 2, 'e': 2})

        assert self.possession('a') == 1, self.possession('a')
        assert self.possession('b') == 0, self.possession('b')
        assert self.possession('c') == 0, self.possession('c')
        assert self.possession('d') == 0, self.possession('d')
        assert self.possession('e') == 0, self.possession('e')
        expected = (2 * (0.2 * 1 ** 0.5 + 0.2 * 2 ** 0.5 + 0.2 *
                    2 ** 0.5 + 0.2 * 2 ** 0.5 + 0.2 * 2 ** 0.5) **
                    (1 / 0.5))
        assert is_zero(self.possession('consumption_good') - expected), (
            self.possession('consumption_good'), expected)
        self.destroy('a', 1)
        self.destroy('consumption_good', expected)
Ejemplo n.º 15
0
    def production(self):
        if self.id == 0:
            self.create('a', 2)
            self.create('b', 2)
            self.produce({'a': 1, 'b': 2})

            assert self.possession('a') == 1, self.possession('a')
            assert self.possession('b') == 1.8, self.possession('b')
            assert self.possession(
                'consumption_good') == 1**0.5 * 2, self.possession(
                    'consumption_good')
            self.destroy('a', 1)
            self.destroy('b', 1.8)
            self.destroy('consumption_good', 1**0.5 * 2)

            output = self.predict_produce_output({'a': 10, 'b': 10})
            assert output['consumption_good'] == max(10**2, 10**0.5 * 10)

            input = self.predict_produce_input({'a': 10, 'b': 10})
            assert input['a'] == 10, input['a']
            assert input['b'] == 1, input['b']

            nv = self.net_value(output, input, {
                'consumption_good': 10,
                'a': 1,
                'b': 2
            })
            assert nv == 100 * 10 - (10 * 1 + 1 * 2), nv

        elif self.id == 1:
            self.create('a', 2)
            self.create('b', 2)
            self.produce({'a': 1, 'b': 2})

            assert self.possession('a') == 1, self.possession('a')
            assert self.possession('b') == 0, self.possession('b')
            assert self.possession('consumption_good') == 5 * \
                1 ** 2 * 2 ** 1, self.possession('consumption_good')
            self.destroy('a', 1)
            self.destroy('consumption_good', 5 * 1**2 * 2**1)

        elif self.id == 2:
            self.create('a', 2)
            self.create('b', 2)
            self.produce({'a': 1, 'b': 2})

            assert self.possession('a') == 1, self.possession('a')
            assert self.possession('b') == 0, self.possession('b')
            assert self.possession('consumption_good') == min(
                1 * 3, 2 * 1), self.possession('consumption_good')
            self.destroy('a', 1)
            self.destroy('consumption_good', min(1 * 3, 2 * 1))

        elif self.id == 3:
            self.create('a', 10)
            self.create('b', 10)
            self.create('c', 10)
            self.produce({'a': 1, 'b': 2, 'c': 5})

            assert self.possession('a') == 9, self.possession('a')
            assert self.possession('b') == 9.8, self.possession('b')
            assert self.possession('c') == 10, self.possession('c')
            assert self.possession('soft_rubber') == 1**0.25 * 2**0.5 * 5**0.25
            assert self.possession('hard_rubber') == 1**0.1 * 2**0.2 * 5**0.01
            assert self.possession('waste') == 2 / 2, self.possession('waste')
            self.destroy('a')
            self.destroy('b')
            self.destroy('c')
            self.destroy('soft_rubber')
            self.destroy('hard_rubber')
            self.destroy('waste')

        elif self.id == 4:
            input_goods = {'wheels': 4, 'chassi': 1}
            price_vector = {'wheels': 10, 'chassi': 100, 'car': 1000}
            nv = self.predict_net_value(input_goods, price_vector)
            assert nv == 860

        elif self.id == 5:
            self.create('a', 2)
            self.create('b', 2)
            self.create('c', 4)
            self.produce({'a': 1, 'b': 2, 'c': 4})

            assert self.possession('a') == 1, self.possession('a')
            assert self.possession('b') == 0, self.possession('b')
            assert self.possession('c') == 0, self.possession('c')
            expected = (0.25 * 1**0.5 + 0.25 * 2**0.5 + 0.5 * 4**0.5)**(1 /
                                                                        0.5)
            assert self.possession('consumption_good') == expected, (
                self.possession('consumption_good'), expected)
            self.destroy('a', 1)
            self.destroy('consumption_good', expected)

        elif self.id == 6:
            self.create('a', 2)
            self.create('b', 2)
            self.create('c', 2)
            self.create('d', 2)
            self.create('e', 2)
            self.produce({'a': 1, 'b': 2, 'c': 2, 'd': 2, 'e': 2})

            assert self.possession('a') == 1, self.possession('a')
            assert self.possession('b') == 0, self.possession('b')
            assert self.possession('c') == 0, self.possession('c')
            assert self.possession('d') == 0, self.possession('d')
            assert self.possession('e') == 0, self.possession('e')
            expected = 2 * (0.2 * 1**0.5 + 0.2 * 2**0.5 + 0.2 * 2**0.5 +
                            0.2 * 2**0.5 + 0.2 * 2**0.5)**(1 / 0.5)
            assert is_zero(self.possession('consumption_good') -
                           expected), (self.possession('consumption_good'),
                                       expected)
            self.destroy('a', 1)
            self.destroy('consumption_good', expected)