Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Constraint function
#3
Thanks a lot. Here are my attempts. The constraints are not obeyed in the results
N = 1; 
T =24;
P = 10
E = 20 
dt = 1 # 
eta_c = 0.8 
eta_d = 0.9 
e0 = 0.95* E 
t = 0.02

p_c = np.linspace(0, P, T, endpoint=True)  
p_d = np.linspace(0, P, T, endpoint=False)   
A =   np.tri(T)     # lower trinagular matrix
II = np.ones(T)
e = cp.Variable((T,N))

e = t*II*x0 + eta_c*A@p_c - A@p_d/eta_d 
e[0] = e0
# use a for loop to define the unit constriant over each time period
const = []
for k in range(T-1):  # go through each period
#         const.append(x[0] == e0)
        #e[k+1] = t*x[k] + eta_c*p_c[k] - p_d[k]/eta_d 

        p_c[k]*p_d[k] == 0               
        p_c[k] >= 0           
        p_c[k] <= P           
        p_d[k] >= 0            
        p_d[k] <= P            
        e[k+1] >= 0
        e[k+1] <= E
Yoriz write Dec-27-2022, 01:35 PM:
Please post all code, output and errors (in their entirety) between their respective tags. Refer to BBCode help topic on how to post. Use the "Preview Post" button to make sure the code is presented as you expect before hitting the "Post Reply/Thread" button.
Reply


Messages In This Thread
Constraint function - by tman - Dec-27-2022, 08:50 AM
RE: Constraint function - by Larz60+ - Dec-27-2022, 10:16 AM
RE: Constraint function - by tman - Dec-27-2022, 11:03 AM
RE: Constraint function - by tman - Dec-27-2022, 01:48 PM
RE: Constraint function - by ndc85430 - Dec-27-2022, 01:52 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Cross word puzzle solve using python constraint library aliyark145 1 3,342 Nov-29-2018, 10:53 AM
Last Post: Larz60+

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020