Linear Programming with cvxpy

2024/9/20 19:48:00

I would like to ask you regarding on the Linear Program for optimization.

I have an objective function, and constraint functions as below,

  • variables(x1, x2, x3, x4, x5, x6) are quantities of the products, and the quantities of products have to be fixed numbers now.
  • the goal of this problem is the optimizing the quantities of products.

    1. Objective Function (c.T * [x1, x2, x3, x4, x5, x6])

      [[c11, c12, c13, c14, c15 c16],[c21, c22, c23, c24, c25, c26],X     [x1, x2, x3, x4, x5, x6]  
      [c31, c32, c33, c34, c35, c36],[c41, c42, c43, c44, c45, c45]]
      

    The result that I would like to optimize is going to be as below

    c11*x1 + c12*x2 + c13*x3 + c14*x4 + c15*x5 + c16*x6 +
    c21*x1 + c22*x2 + c23*x3 + c24*x4 + c25*x5 + c26*x6 + 
    c31*x1 + c32*x2 + c33*x3 + c34*x4 + c35*x5 + c36*x6 + 
    c41*x1 + c42*x2 + c43*x3 + c44*x4 + c45*x5 + c46*x6 = optimized value
    
    1. Constraint Function

    1) constraint_1

    5500000*x1+2500000*x2+825000*x3+5500000*x4+5500000*x5+5500000*x6 <= 800000000

    2) constraint_2

    x1 <= 10
    x2 <= 10
    x3 <= 10
    x4 <= 10
    x5 <= 10
    x6 <= 10
    

The problem that I am suffering from is the in the "Objective Function of Cs(c1,1 ~ c4,5)".

I have solved the Linear Programming that has integers values in the Objective Functions, but not the matrix.

I have tried all other ways that I could, but now I really need helps on this.

Please kindly suggest me any kind of ideas or codes for this question.

Answer

Suppose you have store the original cij in a numpy array, you might like to sum up terms like c11+c21+c31+c41 first. This can be done by summing up each column, try c.sum(axis = 0)

>>> import numpy as np
>>> c = np.arange(24).reshape(4,6)
>>> c
array([[ 0,  1,  2,  3,  4,  5],[ 6,  7,  8,  9, 10, 11],[12, 13, 14, 15, 16, 17],[18, 19, 20, 21, 22, 23]])
>>> c = c.sum(axis=0)
>>> c
array([36, 40, 44, 48, 52, 56])
https://en.xdnf.cn/q/119294.html

Related Q&A

Program runs forever without giving an error when plotting data only on continent [closed]

Its difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying thi…

KeyError while perfoming solve of two equation

1st i need to get two equation of two longest line length i put lenghths with eq in list like these [( length 1 , eq 1 ) ,.....] sort list with reverse get two equation of two longest line when run the…

Most Pythonic way to merge two dictionnaries having common key/value pair

I have two lists of python dictionnaries : l1 = [{"id":1, "name":"A"}, {"id":2, "name":"B"}] l2 = [{"id":1, "full_name":&…

How to close a while True loop instantly Python

I have a problem ... How can i press P on my keyboard and close the entire program faster ( i would like instantly ) ? The script that i made runs in a loop ( Loop B ) and checks for an image on deskt…

How to replace a value in a list

the program asks user to enter 5 unique number, if the number is already in the list, ask for a new number. after 5 unique numbers have been entered, display the listnumbers = [1,2,3,4,5] count = 0 ind…

How To Reverse A Nested Python List

Given the following nested list,myList=([1,[2,3],[[4,5,[6],7],8,9]])I want to reverse it to be converted into:myList= [[[4, 5, [6], 7], 8, 9], [2, 3], 1]How do I do that? Thanks.

Extract street address from a string

Is there any way to extract a street address from a string (say, email) using python? The address does not come in a set format. It can come without state, zip code, city, but I can guess and supply t…

Convert list in String format back to list of float numbers

str = [ 3.82133931e-01 4.27354313e-02 1.94678816e-03 0.00000000e+000.00000000e+00 0.00000000e+00 0.00000000e+00 0.00000000e+000.00000000e+00 0.00000000e+00 0.00000000e+00 0.00000000e…

Hawaiian Pronunciation [duplicate]

This question already has an answer here:Hawaiian pronouncer(1 answer)Closed 1 year ago.Hitting a snag with an assignment and thought Id ask for help. The goal is to be able to pronounce Hawaiian words…

mutiline python script in html (pyscript)

Ive tried to use pyscript in html but i can only get it to work in one line of code can somebody help me get it to work for the following code? def vpn(website):from selenium import webdriverfrom sele…