Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8878037
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T19:36:57+00:00 2026-06-14T19:36:57+00:00

This program: from __future__ import division import numpy as np from scipy.optimize import minimize

  • 0

This program:

from __future__ import division
import numpy as np
from scipy.optimize import minimize
from collections import deque

def buy_captial():
    """ buys the profit maximizing amount of captial """
    offers = {'W': [{'quantity':50, 'price': 1}],
              'K': [{'quantity':200, 'price': 0.5}]}
    key_order = ('W', 'K')
    exponents = {'W': 0.6, 'K': 0.4}

    prices = {}
    quantities = {}
    for key in key_order:
        if key in offers:
            prices[key] = deque([offers[key][i]['price'] for i in range(len(offers[key]))])
            quantities[key] = deque([offers[key][i]['quantity'] for i in range(len(offers[key]))])

    print quantities
    budget = [{'type': 'ineq', 'fun': lambda x:
                                        200
                                        - sum([x[i] * prices[key_order[i]][0] for i in rng])}]
    rng = range(len(key_order))
    x0 = np.zeros(len(key_order))
    bounds =  ((0, 50), (0, 200))

    def objective(x):
        return \
            - 5  * np.prod([(x[i]) ** exponents[key_order[i]] for i in rng]) \
            + sum([x[i] * prices[key_order[i]][0] for i in rng])


    res = minimize(objective, x0=x0, method='SLSQP', constraints=budget, bounds=bounds)
    print 'buy', res,

buy_captial()

leads to this error:

python test_buy_captial.py 
{'K': deque([200]), 'W': deque([50])}
Traceback (most recent call last):
  File "test_buy_captial.py", line 37, in <module>
    buy_captial()
  File "test_buy_captial.py", line 34, in buy_captial
    res = minimize(objective, x0=x0, method='SLSQP', constraints=budget, bounds=bounds)
  File "/usr/local/lib/python2.7/dist-packages/scipy/optimize/_minimize.py", line 358, in minimize
    constraints, **options)
  File "/usr/local/lib/python2.7/dist-packages/scipy/optimize/slsqp.py", line 333, in _minimize_slsqp
    xl[infbnd[:, 0]] = -1.0E12
OverflowError: Python int too large to convert to C long
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T19:36:58+00:00Added an answer on June 14, 2026 at 7:36 pm

    The problem is that the bounds are specified, as integers. The Fortran backbone can’t convert that.
    The solution is to specify the bounds as float. Either by the ‘float()’ argument or better for speed as pointed out by @pv. by bounds = array([[0, 50], [0, 200]], dtype=float)

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I can't figure out why this program is failing. #!/usr/bin/env python from __future__ import
Code first: '''this is main structure of my program''' from twisted.web import http from
I wrote a program called Hello.py that looks like this: import pygame, sys from
Below is the program that I wrote. /******************************************************************************* * This program reads EOF from
This is with reference to the below question: Execute program from within a C
I'm running this small C# test program launched from a pre-commit batch file private
I have this two tables from my program to manage stock: Articulos (items): id_articulo
This is a clojure program to read integers from a file and count the
I need to run this line from my c++ program: java -jar test.jar text1
I have a text file exported from a Foxpro (Dos-based) program, but this text

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.