optimization - Writing constraint in CPLEX OPL -
i have problem in writing constraint. have 1 mobile phone number, 4 tariff package , 9 months. now, solution giving different tariff each month. write constraint solution gives same tariff each model
//data {string} numbers = ...;//mobile phone number, id, 1 number {string} usagecategories = ...;//{"fixed""mobile""international""data"} tuple packageinfo { string name; float price; float fixedminutes; float mobileminutes; float internationalminutes; float data; }; {packageinfo} packages = ...;//tariff package info float usagefixed[numbers] = ...;//fixed min used float usagemobile[numbers] = ...;//mobile other min used float usageinternational[numbers] = ...;//international numbers used float usagedata[numbers] = ...; //data traffic (kb) float taxfree[numbers] = ...; //tax free items float internationalservices[numbers] = ...; //international services float priceperminute[usagecategories] = ...;//price per minute after minutes included in package //minutes included in package each number...calculated in execute block overagefactor float overagefixed[numbers][packages]; float overagemobile[numbers][packages]; float overageinternational[numbers][packages]; float overagedata[numbers][packages]; //decision vars dvar boolean assign[numbers][packages]; //overage amount execute overagefactor { (var n in numbers) { (var p in packages) { if (usagefixed[n] < p.fixedminutes) overagefixed[n][p] = 0; else overagefixed[n][p] = usagefixed[n] - p.fixedminutes; if (usagemobile[n] < p.mobileminutes) overagemobile[n][p] = 0; else overagemobile[n][p] = usagemobile[n] - p.mobileminutes; if (usageinternational[n] < p.internationalminutes) overageinternational[n][p] = 0; else overageinternational[n][p] = usageinternational[n] - p.internationalminutes; if (usagedata[n] < p.data) overagedata[n][p] = 0; else overagedata[n][p] = usagedata[n] - p.data; } } }; dexpr float packagescost = sum (n in numbers, p in packages) p.price * assign[n][p]; //package cost //overage costs dexpr float fixedoveragecost[p in packages, n in numbers] = overagefixed[n][p] * assign[n][p] * priceperminute["fixed"]; dexpr float mobileoveragecost[p in packages, n in numbers] = overagemobile[n][p] * assign[n][p] * priceperminute["mobile"]; dexpr float internationaloveragecost[p in packages, n in numbers] = overageinternational[n][p] * assign[n][p] * priceperminute["international"]; dexpr float dataoveragecost[p in packages, n in numbers] = overagedata[n][p] * assign[n][p] * priceperminute["data"]; dexpr float cost = packagescost + sum (p in packages, n in numbers) (fixedoveragecost[p,n] + mobileoveragecost[p,n] + internationaloveragecost[p,n] + dataoveragecost[p,n]) + sum (n in numbers) taxfree[n] + sum (n in numbers) internationalservices[n]; //objective minimize cost; //constraints subject { //one package each number forall (n in numbers) sum (p in packages) assign[n,p] == 1; //every month same package ????????????????????????? }; //data display tuple assignedpackage { string id; string package; }; {assignedpackage} assignedpackages = {<i,p.name> | in numbers, p in packages : assign[i,p] == 1}; execute datadisplay { writeln ("assign following packages users:"); (var in assignedpackages) writeln (i); } current solution: <"7" "vpn za sve s"> <"6" "vpn za sve l"> <"8" "vpn za sve s"> <"9" "vpn za sve s"> <"10" "vpn za sve l"> <"11" "vpn za sve m"> <"12" "vpn za sve m"> <"1" "vpn za sve s"> <"2" "vpn za sve m">
Comments
Post a Comment