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 4006364
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T08:30:21+00:00 2026-05-20T08:30:21+00:00

I need to solve a problem. I have 5 devices. They all have 4

  • 0

I need to solve a problem. I have 5 devices. They all have 4 kind of I/O types. And there is a target input/output combination. At first step, I want to find all combinations among the devices so that the total I/O number of selected devices are all equal or greater than the target values. Let me explain:

# Devices=[numberof_AI,numberof_AO,numberof_BI,numberof_BO,price]

Device1=[8,8,4,4,200]
Device1=[16,0,16,0,250]
Device1=[8,0,4,4,300]
Device1=[16,8,4,4,300]
Device1=[8,8,2,2,150]

Target=[24,12,16,8]

There are constraints as well. In combinations, max. number of devices can be 5 at most.

At the second step, among the combinations found, I will pick the cheapest one.

Actually, I managed to solve this problem with for loops in Python. I works like a charm. But it takes too much time even though I use cython.

What other options can I benefit from for this kind of problem?

  • 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-05-20T08:30:22+00:00Added an answer on May 20, 2026 at 8:30 am

    You can use a linear programming package like PuLP. (note this also requires you to install an LP library like GLPK).

    Here’s how you would use it to solve the example you gave:

    import pulp
    
    prob = pulp.LpProblem("example", pulp.LpMinimize)
    
    # Variable represent number of times device i is used
    n1 = pulp.LpVariable("n1", 0, 5, cat="Integer")
    n2 = pulp.LpVariable("n2", 0, 5, cat="Integer")
    n3 = pulp.LpVariable("n3", 0, 5, cat="Integer")
    n4 = pulp.LpVariable("n4", 0, 5, cat="Integer")
    n5 = pulp.LpVariable("n5", 0, 5, cat="Integer")
    
    # Device params
    Device1=[8,8,4,4,200]
    Device2=[16,0,16,0,250]
    Device3=[8,0,4,4,300]
    Device4=[16,8,4,4,300]
    Device5=[8,8,2,2,150]
    
    # The objective function that we want to minimize: the total cost
    prob += n1 * Device1[-1] + n2 * Device2[-1] + n3 * Device3[-1] + n4 * Device4[-1] + n5 * Device5[-1]
    
    # Constraint that we use no more than 5 devices
    prob += n1 + n2 + n3 + n4 + n5 <= 5
    
    Target = [24, 12, 16, 8]
    
    # Constraint that the total I/O for all devices exceeds the target
    for i in range(4):
        prob += n1 * Device1[i] + n2 * Device2[i] + n3 * Device3[i] + n4 * Device4[i] + n5 * Device5[i] >= Target[i]
    
    # Actually solve the problem, this calls GLPK so you need it installed
    pulp.GLPK().solve(prob)
    
    # Print out the results
    for v in prob.variables():
        print v.name, "=", v.varValue
    

    Running this is extremely fast, and I get that n1 = 2 and n2 = 1 and the others are 0.

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

Sidebar

Related Questions

I need to solve the following problem for one of my clients. They have
I need some ideas on how I can best solve this problem. I have
A problem that we need to solve regularly at my workplace is how to
I have a problem and I have no idea how to solve it. I
Does anyone know a good way to solve this other problem I have. My
I need to programmatically solve a system of linear equations in C, Objective C,
The situation I'm trying to solve: in my Cocoa app, I need to encrypt
need ask you about some help. I have web app running in Net 2.0.
I have spent all Friday and Saturday on this and I am running out
I have a problem. Part of my app requires text to be shown in

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.