<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic How to add constant in SASOPTY in Mathematical Optimization, Discrete-Event Simulation, and OR</title>
    <link>https://communities.sas.com/t5/Mathematical-Optimization/How-to-add-constant-in-SASOPTY/m-p/521730#M2520</link>
    <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;I'm not sure if it's the right forum to ask any question related to sasoptpy here.Please delete it if it's not the right forum&lt;/P&gt;&lt;P&gt;I'm doing optimization in python using sasoptpy.My objective function looks like z=(a*p+q*b)*c. where all of these variables are columns of a data frame.&lt;/P&gt;&lt;P&gt;a,p,q,b are my variables &amp;amp; c is constant.&lt;/P&gt;&lt;P&gt;I'm defining a,b,p,q in following way&amp;nbsp; va=m.add_variable(a, name='va',lb=LB2,ub=UB2). But not sure how to define constant c. Can you please suggest.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Sat, 15 Dec 2018 18:01:25 GMT</pubDate>
    <dc:creator>Leesa</dc:creator>
    <dc:date>2018-12-15T18:01:25Z</dc:date>
    <item>
      <title>How to add constant in SASOPTY</title>
      <link>https://communities.sas.com/t5/Mathematical-Optimization/How-to-add-constant-in-SASOPTY/m-p/521730#M2520</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;I'm not sure if it's the right forum to ask any question related to sasoptpy here.Please delete it if it's not the right forum&lt;/P&gt;&lt;P&gt;I'm doing optimization in python using sasoptpy.My objective function looks like z=(a*p+q*b)*c. where all of these variables are columns of a data frame.&lt;/P&gt;&lt;P&gt;a,p,q,b are my variables &amp;amp; c is constant.&lt;/P&gt;&lt;P&gt;I'm defining a,b,p,q in following way&amp;nbsp; va=m.add_variable(a, name='va',lb=LB2,ub=UB2). But not sure how to define constant c. Can you please suggest.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 15 Dec 2018 18:01:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Mathematical-Optimization/How-to-add-constant-in-SASOPTY/m-p/521730#M2520</guid>
      <dc:creator>Leesa</dc:creator>
      <dc:date>2018-12-15T18:01:25Z</dc:date>
    </item>
    <item>
      <title>Re: How to add constant in SASOPTY</title>
      <link>https://communities.sas.com/t5/Mathematical-Optimization/How-to-add-constant-in-SASOPTY/m-p/521915#M2521</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Constants are defined as regular Python values (floats or integers), such as&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;c = 5&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;and can be used in expressions.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you would like to use the value in dataframe, you can access the actual value as:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;c = df.at[0, 'c']&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Here's a full example:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;import pandas as pd

# Define dataframe
df = pd.DataFrame([[4, 5, 6]], columns=['a', 'b', 'c'])

# Define model
m = so.Model(name='model1', session=None)

# Get columns
a = df['a']
b = df['b']
c = df.at[0, 'c']

# Define variables
va = m.add_variables(a.index.tolist(), name='va')
vb = m.add_variables(b.index.tolist(), name='vb')

# Set objective
obj = m.set_objective((va.mult(a) + vb.mult(b)) * c, name='obj')

# Print the objective function
print(m.get_objective())&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;This will print the objective function as&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;24 * va[0] + 30 * vb[0]&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;If this doesn't solve your problem, could you provide a minimal working example?&lt;/P&gt;</description>
      <pubDate>Mon, 17 Dec 2018 14:10:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Mathematical-Optimization/How-to-add-constant-in-SASOPTY/m-p/521915#M2521</guid>
      <dc:creator>sertalpb</dc:creator>
      <dc:date>2018-12-17T14:10:37Z</dc:date>
    </item>
  </channel>
</rss>

