|
| 1 | +/** |
| 2 | +* Copyright 2015 IBM Corp. All Rights Reserved. |
| 3 | +* |
| 4 | +* Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | +* you may not use this file except in compliance with the License. |
| 6 | +* You may obtain a copy of the License at |
| 7 | +* |
| 8 | +* http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | +* |
| 10 | +* Unless required by applicable law or agreed to in writing, software |
| 11 | +* distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | +* See the License for the specific language governing permissions and |
| 14 | +* limitations under the License. |
| 15 | +* |
| 16 | +*/ |
| 17 | + |
| 18 | + |
| 19 | +using UnityEngine; |
| 20 | +using System.Collections; |
| 21 | +using System.Collections.Generic; |
| 22 | +using IBM.Watson.DeveloperCloud.Services.TradeoffAnalytics.v1; |
| 23 | + |
| 24 | +public class ExampleTradeoffAnalytics : MonoBehaviour { |
| 25 | + TradeoffAnalytics m_TradeoffAnalytics = new TradeoffAnalytics(); |
| 26 | + |
| 27 | + void Start () { |
| 28 | + Problem problemToSolve = new Problem(); |
| 29 | + problemToSolve.subject = "Test Subject"; |
| 30 | + |
| 31 | + List<Column> listColumn = new List<Column>(); |
| 32 | + Column columnPrice = new Column(); |
| 33 | + columnPrice.description = "Price Column to minimize"; |
| 34 | + columnPrice.range = new ValueRange(); |
| 35 | + ((ValueRange)columnPrice.range).high = 600; |
| 36 | + ((ValueRange)columnPrice.range).low = 0; |
| 37 | + columnPrice.type = "numeric"; |
| 38 | + columnPrice.key = "price"; |
| 39 | + columnPrice.full_name = "Price"; |
| 40 | + columnPrice.goal = "min"; |
| 41 | + columnPrice.is_objective = true; |
| 42 | + columnPrice.format = "$####0.00"; |
| 43 | + |
| 44 | + Column columnWeight = new Column(); |
| 45 | + columnWeight.description = "Weight Column to minimize"; |
| 46 | + columnWeight.type = "numeric"; |
| 47 | + columnWeight.key = "weight"; |
| 48 | + columnWeight.full_name = "Weight"; |
| 49 | + columnWeight.goal = "min"; |
| 50 | + columnWeight.is_objective = true; |
| 51 | + columnWeight.format = "####0 g"; |
| 52 | + |
| 53 | + Column columnBrandName = new Column(); |
| 54 | + columnBrandName.description = "All Brand Names"; |
| 55 | + columnBrandName.type = "categorical"; |
| 56 | + columnBrandName.key = "brand"; |
| 57 | + columnBrandName.full_name = "Brand"; |
| 58 | + columnBrandName.goal = "max"; |
| 59 | + columnBrandName.is_objective = true; |
| 60 | + columnBrandName.preference = new string[]{"Samsung", "Apple", "HTC"}; |
| 61 | + columnBrandName.range = new CategoricalRange(); |
| 62 | + ((CategoricalRange)columnBrandName.range).keys = new string[]{"Samsung", "Apple", "HTC"}; |
| 63 | + |
| 64 | + listColumn.Add(columnPrice); |
| 65 | + listColumn.Add(columnWeight); |
| 66 | + // listColumn.Add(columnBrandName); |
| 67 | + |
| 68 | + problemToSolve.columns = listColumn.ToArray(); |
| 69 | + |
| 70 | + |
| 71 | + List<Option> listOption = new List<Option>(); |
| 72 | + |
| 73 | + Option option1 = new Option(); |
| 74 | + option1.key = "1"; |
| 75 | + option1.name = "Samsung Galaxy S4"; |
| 76 | + option1.values = new TestDataValue(); |
| 77 | + (option1.values as TestDataValue).weight = 130; |
| 78 | + (option1.values as TestDataValue).brand = "Samsung"; |
| 79 | + (option1.values as TestDataValue).price = 249; |
| 80 | + listOption.Add(option1); |
| 81 | + |
| 82 | + Option option2 = new Option(); |
| 83 | + option2.key = "2"; |
| 84 | + option2.name = "Apple iPhone 5"; |
| 85 | + option2.values = new TestDataValue(); |
| 86 | + (option2.values as TestDataValue).weight = 112; |
| 87 | + (option2.values as TestDataValue).brand = "Apple"; |
| 88 | + (option2.values as TestDataValue).price = 599; |
| 89 | + listOption.Add(option2); |
| 90 | + |
| 91 | + Option option3 = new Option(); |
| 92 | + option3.key = "3"; |
| 93 | + option3.name = "HTC One"; |
| 94 | + option3.values = new TestDataValue(); |
| 95 | + (option3.values as TestDataValue).weight = 143; |
| 96 | + (option3.values as TestDataValue).brand = "HTC"; |
| 97 | + (option3.values as TestDataValue).price = 299; |
| 98 | + listOption.Add(option3); |
| 99 | + |
| 100 | + problemToSolve.options = listOption.ToArray(); |
| 101 | + |
| 102 | + m_TradeoffAnalytics.GetDilemma( OnGetDilemma, problemToSolve, false ); |
| 103 | + } |
| 104 | + |
| 105 | + private void OnGetDilemma( DilemmasResponse resp ) |
| 106 | + { |
| 107 | + Debug.Log("Response: " + resp); |
| 108 | + } |
| 109 | + |
| 110 | + /// <summary> |
| 111 | + /// Application data value. |
| 112 | + /// </summary> |
| 113 | + public class TestDataValue : IBM.Watson.DeveloperCloud.Services.TradeoffAnalytics.v1.ApplicationDataValue |
| 114 | + { |
| 115 | + public double price { get; set; } |
| 116 | + public double weight { get; set; } |
| 117 | + public string brand { get; set; } |
| 118 | + } |
| 119 | + |
| 120 | + /// <summary> |
| 121 | + /// Application data. |
| 122 | + /// </summary> |
| 123 | + public class TestData : IBM.Watson.DeveloperCloud.Services.TradeoffAnalytics.v1.ApplicationData |
| 124 | + { |
| 125 | + |
| 126 | + } |
| 127 | +} |
0 commit comments