Optimization Action Set
Loading an MPS File
This section contains PROC CAS code.
Note: Input data must be accessible in your CAS session, either as a CAS table or as a transient-scope table. A CAS table has a two-level name: the first level is your CAS engine libref, and the second level is the table name. You refer to this table in the CAS procedure by specifying only the second level. For more information about two-level names, see Chapter 3, Shared Concepts (SAS Optimization: Mathematical Optimization Procedures). A transient-scope table is called directly from the action and exists in memory for the duration of the action. For more information about accessing data, see SAS Viya: System Programming Guide. For more information about PROC CAS and programming in CASL, see SAS Cloud Analytic Services: CASL Programmer’s Guide and SAS Cloud Analytic Services: CASL Reference.
The example illustrates how you can use the loadMps action to make a problem instance available to solver actions. It uses example_fix.mps, the MPS file shown in Example 8.2: Fixed-MPS-Format File (SAS Optimization: Mathematical Optimization Procedures).
The following CASL statements first use the READPATH function to read the contents of example_fix.mps into the string variable example_fix_string. The loadMps action then reads example_fix_string, which is passed in as the mpsFileString parameter, and saves the output table as "example_fix," replacing an existing table of the same name if one exists and treating the mpsFileString parameter as having a fixed format. The maxLength parameter takes the default value of 8.
proc cas;
example_fix_string = readpath ("example_fix.mps");
loadactionset "optimization";
action optimization.loadMps /
mpsFileString = example_fix_string
casOut = {name = "example_fix" replace = true}
format = "FIXED";
run;
action table.fetch / table = "example_fix" to = 24;
run;
quit;
The data table example_fix, which is displayed in Output 2.2.1, shows the data table that the action produces. Note that the resulting table is different from the one that the convertMps action produces in Example 2.1: Converting to an MPS-Format Data Table. They still produce the same results from the solver because Field1–Field6 are the same when they are sorted by the _ID_ column.
Output 2.2.1: Loaded Data Table
| Selected Rows from Table EXAMPLE_FIX | |||||||
|---|---|---|---|---|---|---|---|
| _Index_ | Field1 | Field2 | Field3 | Field4 | Field5 | Field6 | _id_ |
| 1 | NAME | PROD_MIX | . | . | 1 | ||
| 2 | ROWS | . | . | 2 | |||
| 3 | N | PROFIT | . | . | 3 | ||
| 4 | L | STAMP | . | . | 4 | ||
| 5 | L | ASSEMB | . | . | 5 | ||
| 6 | L | FINISH | . | . | 6 | ||
| 7 | COLUMNS | . | . | 7 | |||
| 8 | DESK | STAMP | 3 | ASSEMB | 10 | 8 | |
| 9 | DESK | FINISH | 10 | PROFIT | -95 | 9 | |
| 10 | CHAIR | STAMP | 1.5 | ASSEMB | 6 | 10 | |
| 11 | CHAIR | FINISH | 8 | PROFIT | -41 | 11 | |
| 12 | CABINET | STAMP | 2 | ASSEMB | 8 | 12 | |
| 13 | CABINET | FINISH | 8 | PROFIT | -84 | 13 | |
| 14 | BOOKCSE | STAMP | 2 | ASSEMB | 7 | 14 | |
| 15 | BOOKCSE | FINISH | 7 | PROFIT | -76 | 15 | |
| 16 | RHS | . | . | 16 | |||
| 17 | TIME | STAMP | 800 | ASSEMB | 1200 | 17 | |
| 18 | TIME | FINISH | 800 | . | 18 | ||
| 19 | RANGES | . | . | 19 | |||
| 20 | T1 | ASSEMB | 900 | . | 20 | ||
| 21 | BOUNDS | . | . | 21 | |||
| 22 | UP | BND | CHAIR | 75 | . | 22 | |
| 23 | LO | BND | BOOKCSE | 50 | . | 23 | |
| 24 | ENDATA | . | . | 24 | |||
Loading an MPS File
This section contains Lua code for the analysis in the CASL version of this example, which contains details about the results.
For more information about coding in Lua, see Getting Started with SAS Viya for Lua and SAS Viya: System Programming Guide.
This example illustrates how you can use the loadMps action in Lua code to make a problem instance available to solver actions. The following code loads the problem instance from the MPS file, example_fix.mps, in Example 8.2: Fixed-MPS-Format File (SAS Optimization: Mathematical Optimization Procedures):
data = ""
for line in io.lines("example_fix.mps") do
data = data .. line .. "\n"
end
s:optimization_loadMps{
mpsFileString = data,
casOut = {name = "example_fix", replace = true},
format = "FIXED"
}
Loading an MPS File
This section contains Python code for the analysis in the CASL version of this example, which contains details about the results.
For more information about coding in Python, see Getting Started with SAS Viya for Python and SAS Viya: System Programming Guide.
This example illustrates how you can use the loadMps action in Python code to make a problem instance available to solver actions. The following code loads the problem instance from the MPS file, example_fix.mps, in Example 8.2: Fixed-MPS-Format File (SAS Optimization: Mathematical Optimization Procedures):
with open('example_fix.mps', 'r') as myfile:
data = myfile.read()
s.optimization.loadMps(
mpsFileString = data,
casOut = {"name":"example_fix", "replace":True},
format = "FIXED"
)
Loading an MPS File
This section contains R code for the analysis in the CASL version of this example, which contains details about the results.
For more information about coding in R, see Getting Started with SAS Viya for R and SAS Viya: System Programming Guide.
This example illustrates how you can use the loadMps action in R code to make a problem instance available to solver actions. The following code loads the problem instance from the MPS file, example_fix.mps, in Example 8.2: Fixed-MPS-Format File (SAS Optimization: Mathematical Optimization Procedures):
data <- paste(readLines("example_fix.mps"), collapse="\n")
cas.optimization.loadMps(s,
mpsFileString = data,
casOut = list(name="example_fix", replace=TRUE),
format = "FIXED"
)