Original Message:
Sent: Fri July 12, 2024 03:00 AM
From: ALEX FLEISCHER
Subject: CPLEX Operator not available for {float} * {int}
Hi,
you mix sets and scalar values.
Let me fix the objective to help you undestand.
dexpr float SVM = first(Q1)*(sum(j in CommunitiesRange, i in CandidateSitesRange)first(q[j])*n[j]*d[j][i]) + first(Q2)*(sum(j in CommunitiesRange, i in CandidateSitesRange)first(l[i])*first(f[j])*n[j]*d[j][i]);
would work fine.
Q1 is a set. You can use an element of a set in an equation but not the set itself
regards
------------------------------
[Alex] [Fleischer]
[Data and AI Technical Sales]
[IBM]
Original Message:
Sent: Wed July 10, 2024 03:03 PM
From: Omar Abbaas
Subject: CPLEX Operator not available for {float} * {int}
Can you please take a look at this code and help me understand why I am getting the errors below and how to fix them?
int CandidateSites = 13; //Number of candidate locations for SVMs
int Communities = 7; //Number of communities
range CandidateSitesRange = 1..CandidateSites;
range CommunitiesRange = 1..Communities;
// Now we define the parameters
{float} Smax=...; // Max distance a person is willing to travel
{float} B=...; // Budget
{float} Q1=...; // Qaly gained from overdose reversal
{float} Q2=...; // Qaly gained from referral
{float} lambda=...; // Rate of reduction in willingness wot travel
{float} Bth=...; // Accessability score threshold
{int} NR[CandidateSitesRange]=...; // Number of restocks at each location
{float} l[CandidateSitesRange]=...; // Probability of a refferal
{int} K[CandidateSitesRange]=...; // SVM capacity
{float} C1[CandidateSitesRange]=...; // Cost per restock for SVM at location i
{float} C2[CandidateSitesRange]=...; // Annualized fixed cost, plus maintenance cost for SVM at location i
{float} C3[CandidateSitesRange]=...; // Cost per dose of naloxone at location i
{float} q[CommunitiesRange]=...; // Probability a dose is used for overdose reversal
{int} Demand[CommunitiesRange]=...; // Demand at a commuinity
{float} f[CommunitiesRange]=...; // Fraction of demand that has OUD
{float} s[CommunitiesRange][CandidateSitesRange] = ...; // Distance between community j and SVM location i
{float} p[CommunitiesRange][CandidateSitesRange] = ...; // probability one would travel from community to location i
// Define decision variables
dvar boolean Z[CandidateSitesRange];
dvar int d[CommunitiesRange][CandidateSitesRange];
dvar float n[CommunitiesRange];
// Objective function
dexpr float SVM = Q1*(sum(j in CommunitiesRange, i in CandidateSitesRange)q[j]*n[j]*d[j][i]) + Q2*(sum(j in CommunitiesRange, i in CandidateSitesRange)l[i]*f[j]*n[j]*d[j][i]);
// Model
maximize SVM;
subject to{
forall (j in CommunitiesRange)
n[j] == 1;
forall (j in CommunitiesRange, i in CandidateSitesRange)
d[j][i] <= p[j][i]*Demand[j]*Z[i];
forall (j in CommunitiesRange)
sum(i in CandidateSitesRange) d[j][i] <= Demand[j];
sum(i in CandidateSitesRange)((Z[i]*C2[i])+(C3[i]*sum(j in CommunitiesRange)d[j][i])+(C1[i]*sum(j in CommunitiesRange)d[j][i]/K[i])) <= B;
forall (j in CommunitiesRange)
sum(i in CandidateSitesRange) p[j][i]*Z[i] >= Bth;
forall (i in CandidateSitesRange)
sum(j in CommunitiesRange)d[j][i]/K[i] <= NR[i];
forall (j in CommunitiesRange, i in CandidateSitesRange)
d[j][i] >= 0;
}
Errors:
Operator not available for {float} * {int}
Operator not available for {float} * dvar boolean
Operator not available for {float} * dvar float
Operator not available for dexpr int <= {int}
Operator not available for dvar boolean * {float}
Operator not available for dvar int / {int}
------------------------------
Omar Abbaas
------------------------------